Compare commits

1 Commits

Author SHA1 Message Date
hueso
4b129e2632 update documentation 2024-02-13 15:50:31 -03:00
32 changed files with 11302 additions and 5125 deletions

2
.commitlintrc.yaml Normal file
View File

@@ -0,0 +1,2 @@
extends:
- "@commitlint/config-conventional"

3
.czrc Normal file
View File

@@ -0,0 +1,3 @@
{
"path": "cz-conventional-changelog"
}

1
.husky/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
_

4
.husky/commit-msg Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn dlx commitlint --edit $1

4
.husky/pre-commit Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn dlx lint-staged

File diff suppressed because one or more lines are too long

786
.yarn/releases/yarn-3.2.1.cjs vendored Executable file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
compressionLevel: mixed
enableGlobalCache: false
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.9.2.cjs
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
yarnPath: .yarn/releases/yarn-3.2.1.cjs

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
pragma solidity 0.8.19;
import { IReputation } from "./lib/interfaces/IReputation.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
pragma solidity 0.8.19;
import { ERC20, OwnerSettings } from "contracts/core/OwnerSettings.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
pragma solidity 0.8.19;
abstract contract Constants {
/// ███ Constants ██████████████████████████████████████████████████████████
@@ -44,5 +44,4 @@ abstract contract Constants {
uint256 constant MAXBALANCE_UPPERBOUND = 1e8 ether;
uint256 constant REPUTATION_LOWERBOUND = 1e2 ether;
uint256 constant LOCKAMOUNT_UPPERBOUND = 1e6 ether;
uint256 constant BOND_DIVISOR = 4; // 6,25%
}

View File

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

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
pragma solidity 0.8.19;
import { ERC20 } from "contracts/lib/tokens/ERC20.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
pragma solidity 0.8.19;
import { ERC2771Context as ERC2771 } from "contracts/lib/metatx/ERC2771Context.sol";
import { ERC20, SafeTransferLib } from "contracts/lib/utils/SafeTransferLib.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
pragma solidity 0.8.19;
import { ERC20 } from "../tokens/ERC20.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
pragma solidity 0.8.19;
/// ______ __
/// .-----.|__ |.-----.|__|.--.--.
@@ -57,7 +57,7 @@ contract P2PIX is BaseUtils {
ERC20 token,
uint96 amount,
bool valid
) public nonReentrant {
) public {
if (bytes(pixTarget).length == 0) revert EmptyPixTarget();
if (!allowedERC20s(token)) revert TokenDenied();
@@ -68,6 +68,8 @@ contract P2PIX is BaseUtils {
if (_newBal > MAXBALANCE_UPPERBOUND)
revert MaxBalExceeded();
setReentrancyGuard();
if (allowlistRoot != 0) {
setRoot(msg.sender, allowlistRoot);
}
@@ -89,6 +91,8 @@ contract P2PIX is BaseUtils {
amount
);
clearReentrancyGuard();
emit DepositAdded(msg.sender, token, amount);
}
@@ -120,7 +124,7 @@ contract P2PIX is BaseUtils {
/// @notice This method can be performed either by:
/// - An user allowed via the seller's allowlist;
/// - An user with enough userRecord to lock the wished amount;
/// @notice There can only exist a lock per each `amount` partitioned
/// @notice There can only exist a lock per each `_amount` partitioned
/// from the total `remaining` value.
/// @notice Locks can only be performed in valid orders.
/// @param amount The deposit's remaining amount wished to be locked.
@@ -135,8 +139,7 @@ contract P2PIX is BaseUtils {
ERC20 token,
uint80 amount,
bytes32[] calldata merkleProof,
uint256[] calldata expiredLocks,
bool bond
uint256[] calldata expiredLocks
) public nonReentrant returns (uint256 lockID) {
unlockExpired(expiredLocks);
@@ -155,17 +158,10 @@ contract P2PIX is BaseUtils {
bytes32 _pixTarget = getPixTarget(seller, token);
if (bond){
SafeTransferLib.safeTransferFrom(
token,
_msgSender(),
address(this),
amount >> BOND_DIVISOR
);
} else if (merkleProof.length != 0) {
// transaction forwarding must leave `merkleProof` empty;
// otherwise, the trustedForwarder must be previously added
// to a seller whitelist.
// transaction forwarding must leave `merkleProof` empty;
// otherwise, the trustedForwarder must be previously added
// to a seller whitelist.
if (merkleProof.length != 0) {
_merkleVerify( merkleProof, sellerAllowList(seller), _msgSender());
} else if ( amount > REPUTATION_LOWERBOUND && msg.sender == _msgSender() ) {
@@ -186,8 +182,7 @@ contract P2PIX is BaseUtils {
amount,
token,
_msgSender(),
seller,
bond
seller
);
_addLock(bal, l);
@@ -246,7 +241,7 @@ contract P2PIX is BaseUtils {
SafeTransferLib.safeTransfer(
t,
l.buyerAddress,
l.bond ? lockAmount + lockAmount >> BOND_DIVISOR : lockAmount
lockAmount
);
emit LockReleased(l.buyerAddress, lockID, lockAmount);
@@ -275,7 +270,7 @@ contract P2PIX is BaseUtils {
if ((_sellerBalance + l.amount) > MAXBALANCE_UPPERBOUND)
revert MaxBalExceeded();
_addSellerBalance(l.seller, l.token, l.bond ? l.amount + l.amount >> BOND_DIVISOR : l.amount);
_addSellerBalance(l.seller, l.token, l.amount);
l.amount = 0;

View File

@@ -1,9 +1,8 @@
{
"signers": [
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
"0x8963E134E6d22Ee9A26ac62a99964aB391ead816"
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
],
"token": "0xfE841c74250e57640390f46d914C88d22C51e82e",
"p2pix": "0x57Dcba05980761169508886eEdc6f5E7EC0411Dc"
"p2pix": "0x98ba35eb14b38D6Aa709338283af3e922476dE34"
}

View File

@@ -1,8 +0,0 @@
{
"signers": [
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
],
"p2pix": "0xb7cD135F5eFD9760981e02E2a898790b688939fe",
"token": "0x3eBE67A2C7bdB2081CBd34ba3281E90377462289"
}

View File

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

View File

@@ -1,30 +1 @@
# Solidity API
## DataTypes
### Lock
```solidity
struct Lock {
uint256 counter;
uint256 expirationBlock;
bytes32 pixTarget;
uint80 amount;
contract ERC20 token;
address buyerAddress;
address seller;
bool bond;
}
```
### LockStatus
```solidity
enum LockStatus {
Inexistent,
Active,
Expired,
Released
}
```
# DataTypes

View File

@@ -1,54 +1,63 @@
# Solidity API
# EventAndErrors
## EventAndErrors
## Events
### AllowedERC20Updated
```solidity
event AllowedERC20Updated(address indexed token, bool indexed state)
```
#### Parameters
| Name | Type | Description |
| --------------- | ------- | ----------- |
| token `indexed` | address | undefined |
| state `indexed` | bool | undefined |
### DepositAdded
```solidity
event DepositAdded(address seller, contract ERC20 token, uint256 amount)
event DepositAdded(address indexed seller, uint256 depositID, address token, uint256 amount)
```
_0x63d8d7d5e63e9840ec91a12a160d27b7cfab294f6ba070b7359692acfe6b03bf_
███ Events ████████████████████████████████████████████████████████████
### ValidSet
#### Parameters
| Name | Type | Description |
| ---------------- | ------- | ----------- |
| seller `indexed` | address | undefined |
| depositID | uint256 | undefined |
| token | address | undefined |
| amount | uint256 | undefined |
### DepositClosed
```solidity
event ValidSet(address seller, contract ERC20 token, bool state)
event DepositClosed(address indexed seller, uint256 depositID)
```
_0xca585721b6b442dc9183932f7c84dc2880efb67c4da52cc06873e78971105d49_
#### Parameters
| Name | Type | Description |
| ---------------- | ------- | ----------- |
| seller `indexed` | address | undefined |
| depositID | uint256 | undefined |
### DepositWithdrawn
```solidity
event DepositWithdrawn(address seller, contract ERC20 token, uint256 amount)
event DepositWithdrawn(address indexed seller, uint256 depositID, uint256 amount)
```
_0x2cd6435b1b961c13f55202979edd0765a809f69a539d8a477436c94c1211e43e_
#### Parameters
### LockAdded
```solidity
event LockAdded(address buyer, uint256 lockID, address seller, uint256 amount)
```
_0x8fb3989f70bd172a37d15b41b015e48ea09d59329638377304a4198cd0c4ea65_
### LockReleased
```solidity
event LockReleased(address buyer, uint256 lockId, uint256 amount)
```
_0x364537f14276f2a0ce9905588413f96454cbb8fb2e4f5308389307c1098bede8_
### LockReturned
```solidity
event LockReturned(address buyer, uint256 lockId)
```
_0x830501e61b8b075e170b22a430e39454bdb12ed3e9620e586430b6ac00079da5_
| Name | Type | Description |
| ---------------- | ------- | ----------- |
| seller `indexed` | address | undefined |
| depositID | uint256 | undefined |
| amount | uint256 | undefined |
### FundsWithdrawn
@@ -56,39 +65,27 @@ _0x830501e61b8b075e170b22a430e39454bdb12ed3e9620e586430b6ac00079da5_
event FundsWithdrawn(address owner, uint256 amount)
```
_0xeaff4b37086828766ad3268786972c0cd24259d4c87a80f9d3963a3c3d999b0d_
#### Parameters
### RootUpdated
| Name | Type | Description |
| ------ | ------- | ----------- |
| owner | address | undefined |
| amount | uint256 | undefined |
### LockAdded
```solidity
event RootUpdated(address seller, bytes32 merkleRoot)
event LockAdded(address indexed buyer, bytes32 indexed lockID, uint256 depositID, uint256 amount)
```
_0x0b294da292f26e55fd442b5c0164fbb9013036ff00c5cfdde0efd01c1baaf632_
#### Parameters
### AllowedERC20Updated
```solidity
event AllowedERC20Updated(address token, bool state)
```
_0x5d6e86e5341d57a92c49934296c51542a25015c9b1782a1c2722a940131c3d9a_
### TrustedForwarderUpdated
```solidity
event TrustedForwarderUpdated(address forwarder, bool state)
```
_0xbee55516e29d3969d3cb8eb01351eb3c52d06f9e2435bd5a8bfe3647e185df92_
### ReputationUpdated
```solidity
event ReputationUpdated(address reputation)
```
_0xe127cf589a3879da0156d4a24f43b44f65cfa3570de594806b0bfa2fcf06884f_
| Name | Type | Description |
| ---------------- | ------- | ----------- |
| buyer `indexed` | address | undefined |
| lockID `indexed` | bytes32 | undefined |
| depositID | uint256 | undefined |
| amount | uint256 | undefined |
### LockBlocksUpdated
@@ -96,7 +93,49 @@ _0xe127cf589a3879da0156d4a24f43b44f65cfa3570de594806b0bfa2fcf06884f_
event LockBlocksUpdated(uint256 blocks)
```
_0x70fa43ca70216ad905ade86b9e650a691b2ce5a01980d0a81bdd8324141b8511_
#### Parameters
| Name | Type | Description |
| ------ | ------- | ----------- |
| blocks | uint256 | undefined |
### LockReleased
```solidity
event LockReleased(address indexed buyer, bytes32 lockId)
```
#### Parameters
| Name | Type | Description |
| --------------- | ------- | ----------- |
| buyer `indexed` | address | undefined |
| lockId | bytes32 | undefined |
### LockReturned
```solidity
event LockReturned(address indexed buyer, bytes32 lockId)
```
#### Parameters
| Name | Type | Description |
| --------------- | ------- | ----------- |
| buyer `indexed` | address | undefined |
| lockId | bytes32 | undefined |
### ReputationUpdated
```solidity
event ReputationUpdated(address reputation)
```
#### Parameters
| Name | Type | Description |
| ---------- | ------- | ----------- |
| reputation | address | undefined |
### ValidSignersUpdated
@@ -104,81 +143,13 @@ _0x70fa43ca70216ad905ade86b9e650a691b2ce5a01980d0a81bdd8324141b8511_
event ValidSignersUpdated(address[] signers)
```
_0x14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d7_
#### Parameters
### OnlySeller
| Name | Type | Description |
| ------- | --------- | ----------- |
| signers | address[] | undefined |
```solidity
error OnlySeller()
```
_Only seller could call this function.
`msg.sender` and the seller differ.
0x85d1f726_
### NotExpired
```solidity
error NotExpired()
```
_Lock not expired or already released.
Another lock with same ID is not expired yet.
0xd0404f85_
### LoopOverflow
```solidity
error LoopOverflow()
```
_Loop bounds have overflowed.
0xdfb035c9_
### InvalidDeposit
```solidity
error InvalidDeposit()
```
_Deposit not valid anymore.
0xb2e532de_
### NotEnoughTokens
```solidity
error NotEnoughTokens()
```
_Not enough token remaining on deposit.
0x22bbb43c_
### AlreadyReleased
```solidity
error AlreadyReleased()
```
_Lock already released or returned.
0x63b4904e_
### TxAlreadyUsed
```solidity
error TxAlreadyUsed()
```
_Transaction already used to unlock payment.
0xf490a6ea_
### InvalidSigner
```solidity
error InvalidSigner()
```
_Signer is not a valid signer.
0x815e1d64_
## Errors
### AddressDenied
@@ -186,36 +157,15 @@ _Signer is not a valid signer.
error AddressDenied()
```
_Address doesn't exist in a MerkleTree.
Address not allowed as relayer.
0x3b8474be_
_Address doesn't exist in a MerkleTree.Address not allowed as relayer.0x3b8474be_
### LengthMismatch
### AlreadyReleased
```solidity
error LengthMismatch()
error AlreadyReleased()
```
_Arrays' length don't match.
0xff633a38_
### NoTokens
```solidity
error NoTokens()
```
_No tokens array provided as argument.
0xdf957883_
### TokenDenied
```solidity
error TokenDenied()
```
_Token address not allowed to be deposited.
0x1578328e_
_Lock already released or returned.0x63b4904e_
### AmountNotAllowed
@@ -223,56 +173,92 @@ _Token address not allowed to be deposited.
error AmountNotAllowed()
```
_Wished amount to be locked exceeds the limit allowed.
0x1c18f846_
_Wished amount to be locked exceeds the limit allowed.0x1c18f846_
### StaticCallFailed
### DepositAlreadyExists
```solidity
error StaticCallFailed()
error DepositAlreadyExists()
```
_Reverts when success return value returns false.
0xe10bf1cc_
_Deposit already exist and it is still valid.0xc44bd765_
### LockExpired
### InvalidDeposit
```solidity
error LockExpired()
error InvalidDeposit()
```
_Reverts on an expired lock.
0xf6fafba0_
_Deposit not valid anymore.0xb2e532de_
### DecOverflow
### InvalidSigner
```solidity
error DecOverflow()
error InvalidSigner()
```
_0xce3a3d37_
_Signer is not a valid signer.0x815e1d64_
### MaxBalExceeded
### LengthMismatch
```solidity
error MaxBalExceeded()
error LengthMismatch()
```
_0xf3fb0eb9_
_Arrays' length don't match.0xff633a38_
### EmptyPixTarget
### LoopOverflow
```solidity
error EmptyPixTarget()
error LoopOverflow()
```
_0x6a3bc53e_
_Loop bounds have overflowed.0xdfb035c9_
### NotInitialized
### NoTokens
```solidity
error NotInitialized()
error NoTokens()
```
_0x87138d5c_
_No tokens array provided as argument.0xdf957883_
### NotEnoughTokens
```solidity
error NotEnoughTokens()
```
_Not enough token remaining on deposit.0x22bbb43c_
### NotExpired
```solidity
error NotExpired()
```
_Lock not expired or already released.Another lock with same ID is not expired yet.0xd0404f85_
### OnlySeller
```solidity
error OnlySeller()
```
_Only seller could call this function.`msg.sender` and the seller differ.0x85d1f726_
### TokenDenied
```solidity
error TokenDenied()
```
_Token address not allowed to be deposited.0x1578328e_
### TxAlreadyUsed
```solidity
error TxAlreadyUsed()
```
_Transaction already used to unlock payment.0xf490a6ea_

View File

@@ -1,208 +1,694 @@
# Solidity API
# P2PIX
## P2PIX
## Methods
### lockCounter
### \_castAddrToKey
```solidity
uint256 lockCounter
function _castAddrToKey(address _addr) external pure returns (uint256 _key)
```
### mapLocks
Public method that handles `address` to `uint256` safe type casting.
_Function sighash: 0x4b2ae980._
#### Parameters
| Name | Type | Description |
| ------ | ------- | ----------- |
| \_addr | address | undefined |
#### Returns
| Name | Type | Description |
| ----- | ------- | ----------- |
| \_key | uint256 | undefined |
### allowedERC20s
```solidity
mapping(uint256 => struct DataTypes.Lock) mapLocks
function allowedERC20s(contract ERC20) external view returns (bool)
```
_List of Locks._
_Tokens allowed to serve as the underlying amount of a deposit._
### userRecord
#### Parameters
| Name | Type | Description |
| ---- | -------------- | ----------- |
| \_0 | contract ERC20 | undefined |
#### Returns
| Name | Type | Description |
| ---- | ---- | ----------- |
| \_0 | bool | undefined |
### cancelDeposit
```solidity
mapping(uint256 => uint256) userRecord
function cancelDeposit(uint256 depositID) external nonpayable
```
_Stores an relayer's last computed credit._
Enables seller to invalidate future locks made to his/her token offering order.
### constructor
_This function does not affect any ongoing active locks.Function sighash: 0x72fada5c._
#### Parameters
| Name | Type | Description |
| --------- | ------- | ----------- |
| depositID | uint256 | undefined |
### defaultLockBlocks
```solidity
constructor(uint256 defaultBlocks, address[] validSigners, address _reputation, contract ERC20[] tokens, bool[] tokenStates) public payable
function defaultLockBlocks() external view returns (uint256)
```
_Default blocks that lock will hold tokens._
#### Returns
| Name | Type | Description |
| ---- | ------- | ----------- |
| \_0 | uint256 | undefined |
### deposit
```solidity
function deposit(string pixTarget, bytes32 allowlistRoot, contract ERC20 token, uint96 amount, bool valid) public
function deposit(address _token, uint256 _amount, string _pixTarget, bytes32 allowlistRoot) external nonpayable returns (uint256 depositID)
```
Creates a deposit order based on a seller's
offer of an amount of ERC20 tokens.
Seller needs to send his tokens to the P2PIX smart contract.
Creates a deposit order based on a seller's offer of an amount of ERC20 tokens.
_Function sighash: 0x5e918943_
_Seller needs to send his tokens to the P2PIX smart contract.Function sighash: 0xbfe07da6._
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| pixTarget | string | Pix key destination provided by the offer's seller. |
| allowlistRoot | bytes32 | Optional allow list merkleRoot update `bytes32` value. as the deposit identifier. |
| token | contract ERC20 | |
| amount | uint96 | |
| valid | bool | |
| Name | Type | Description |
| ------------- | ------- | ------------------------------------------------------- |
| \_token | address | undefined |
| \_amount | uint256 | undefined |
| \_pixTarget | string | Pix key destination provided by the offer's seller. |
| allowlistRoot | bytes32 | Optional allow list merkleRoot update `bytes32` value. |
### setValidState
#### Returns
| Name | Type | Description |
| --------- | ------- | -------------------------------------------------------------- |
| depositID | uint256 | The `uint256` return value provided as the deposit identifier. |
### depositCount
```solidity
function setValidState(contract ERC20 token, bool state) public
function depositCount() external view returns (uint256 _val)
```
Enables seller to invalidate future
locks made to his/her token offering order.
This function does not affect any ongoing active locks.
#### Returns
_Function sighash: 0x6d82d9e0_
| Name | Type | Description |
| ----- | ------- | ----------- |
| \_val | uint256 | undefined |
### lock
```solidity
function lock(address seller, contract ERC20 token, uint80 amount, bytes32[] merkleProof, uint256[] expiredLocks, bool bond) public returns (uint256 lockID)
function lock(uint256 _depositID, address _buyerAddress, address _relayerTarget, uint256 _relayerPremium, uint256 _amount, bytes32[] merkleProof, bytes32[] expiredLocks) external nonpayable returns (bytes32 lockID)
```
Public method designed to lock an remaining amount of
the deposit order of a seller.
Transaction forwarding must leave `merkleProof` empty;
otherwise, the trustedForwarder must be previously added
to a seller whitelist.
This method can be performed either by:
- An user allowed via the seller'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.
Public method designed to lock an remaining amount of the deposit order of a seller.
_Function sighash: 0xdc43221c_
_This method can be performed either by: - An user allowed via the seller'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
| Name | Type | Description |
| ---- | ---- | ----------- |
| seller | address | |
| token | contract ERC20 | |
| amount | uint80 | The deposit's remaining amount wished to be locked. |
| merkleProof | bytes32[] | Provided as a pass if the `msg.sender` is in the seller's allowlist; Left empty otherwise; |
| expiredLocks | uint256[] | An array of identifiers to be provided so to unexpire locks using this transaction gas push. |
| bond | bool | |
| Name | Type | Description |
| ---------------- | --------- | ------------------------------------------------------------------------------------------------------------------------ |
| \_depositID | uint256 | undefined |
| \_buyerAddress | address | The address of the buyer of a `_depositID`. |
| \_relayerTarget | address | Target address entitled to the `relayerPremim`. |
| \_relayerPremium | uint256 | The refund/premium owed to a relayer. |
| \_amount | uint256 | The deposit'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's allowlist; - Left empty otherwise; |
| expiredLocks | bytes32[] | An array of `bytes32` identifiers to be provided so to unexpire locks using this transaction gas push. |
#### Return Values
#### Returns
| Name | Type | Description |
| ---- | ---- | ----------- |
| lockID | uint256 | The lock identifier. |
| Name | Type | Description |
| ------ | ------- | ---------------------------------------------------- |
| lockID | bytes32 | The `bytes32` value returned as the lock identifier. |
### mapDeposits
```solidity
function mapDeposits(uint256) external view returns (uint256 remaining, string pixTarget, address seller, address token, bool valid)
```
_Seller list of deposits_
#### Parameters
| Name | Type | Description |
| ---- | ------- | ----------- |
| \_0 | uint256 | undefined |
#### Returns
| Name | Type | Description |
| --------- | ------- | ----------- |
| remaining | uint256 | undefined |
| pixTarget | string | undefined |
| seller | address | undefined |
| token | address | undefined |
| valid | bool | undefined |
### mapLocks
```solidity
function mapLocks(bytes32) external view returns (uint256 depositID, uint256 relayerPremium, uint256 amount, uint256 expirationBlock, address buyerAddress, address relayerTarget, address relayerAddress)
```
_List of Locks._
#### Parameters
| Name | Type | Description |
| ---- | ------- | ----------- |
| \_0 | bytes32 | undefined |
#### Returns
| Name | Type | Description |
| --------------- | ------- | ----------- |
| depositID | uint256 | undefined |
| relayerPremium | uint256 | undefined |
| amount | uint256 | undefined |
| expirationBlock | uint256 | undefined |
| buyerAddress | address | undefined |
| relayerTarget | address | undefined |
| relayerAddress | address | undefined |
### owner
```solidity
function owner() external view returns (address)
```
#### Returns
| Name | Type | Description |
| ---- | ------- | ----------- |
| \_0 | address | undefined |
### release
```solidity
function release(uint256 lockID, bytes32 pixTimestamp, bytes signature) public
function release(bytes32 lockID, address _relayerTarget, uint256 pixTimestamp, bytes32 r, bytes32 s, uint8 v) external nonpayable
```
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 relayer 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;
Lock release method that liquidate lock orders and distributes relayer fees.
_Function sighash: 0x11fc7f9a_
_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._
### unlockExpired
#### Parameters
| Name | Type | Description |
| --------------- | ------- | ----------------------------------------------- |
| lockID | bytes32 | undefined |
| \_relayerTarget | address | Target address entitled to the `relayerPremim`. |
| pixTimestamp | uint256 | undefined |
| r | bytes32 | undefined |
| s | bytes32 | undefined |
| v | uint8 | undefined |
### reputation
```solidity
function unlockExpired(uint256[] lockIDs) public
function reputation() external view returns (contract IReputation)
```
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.
███ Storage ████████████████████████████████████████████████████████████
_Function sighash: 0xb0983d39_
#### Returns
### withdraw
| Name | Type | Description |
| ---- | -------------------- | ----------- |
| \_0 | contract IReputation | undefined |
### sellerAllowList
```solidity
function withdraw(contract ERC20 token, uint256 amount, uint256[] expiredLocks) public
function sellerAllowList(uint256) external view returns (bytes32)
```
Seller's expired deposit fund sweeper.
A seller may use this method to recover
tokens from expired deposits.
_Seller casted to key => Seller's allowlist merkleroot._
_Function sighash: 0xfb8c5ef0_
#### Parameters
| Name | Type | Description |
| ---- | ------- | ----------- |
| \_0 | uint256 | undefined |
#### Returns
| Name | Type | Description |
| ---- | ------- | ----------- |
| \_0 | bytes32 | undefined |
### setDefaultLockBlocks
```solidity
function setDefaultLockBlocks(uint256 _blocks) external nonpayable
```
#### Parameters
| Name | Type | Description |
| -------- | ------- | ----------- |
| \_blocks | uint256 | undefined |
### setOwner
```solidity
function setOwner(address newOwner) external nonpayable
```
#### Parameters
| Name | Type | Description |
| -------- | ------- | ----------- |
| newOwner | address | undefined |
### setReputation
```solidity
function setReputation(contract IReputation _reputation) external nonpayable
```
#### Parameters
| Name | Type | Description |
| ------------ | -------------------- | ----------- |
| \_reputation | contract IReputation | undefined |
### setRoot
```solidity
function setRoot(address addr, bytes32 merkleroot) public
function setRoot(address addr, bytes32 merkleroot) external nonpayable
```
### receive
#### Parameters
| Name | Type | Description |
| ---------- | ------- | ----------- |
| addr | address | undefined |
| merkleroot | bytes32 | undefined |
### setValidSigners
```solidity
receive() external payable
function setValidSigners(address[] _validSigners) external nonpayable
```
### _addLock
#### Parameters
| Name | Type | Description |
| -------------- | --------- | ----------- |
| \_validSigners | address[] | undefined |
### tokenSettings
```solidity
function _addLock(uint256 _bal, struct DataTypes.Lock _l) internal
function tokenSettings(address[] _tokens, bool[] _states) external nonpayable
```
### getBalance
#### Parameters
| Name | Type | Description |
| -------- | --------- | ----------- |
| \_tokens | address[] | undefined |
| \_states | bool[] | undefined |
### unlockExpired
```solidity
function getBalance(address seller, contract ERC20 token) public view returns (uint256 bal)
function unlockExpired(bytes32[] lockIDs) external nonpayable
```
### getValid
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._
#### Parameters
| Name | Type | Description |
| ------- | --------- | ----------- |
| lockIDs | bytes32[] | undefined |
### userRecord
```solidity
function getValid(address seller, contract ERC20 token) public view returns (bool valid)
function userRecord(uint256) external view returns (uint256)
```
### getPixTarget
_Stores an relayer's last computed credit._
#### Parameters
| Name | Type | Description |
| ---- | ------- | ----------- |
| \_0 | uint256 | undefined |
#### Returns
| Name | Type | Description |
| ---- | ------- | ----------- |
| \_0 | uint256 | undefined |
### validBacenSigners
```solidity
function getPixTarget(address seller, contract ERC20 token) public view returns (bytes32 pixTarget)
function validBacenSigners(uint256) external view returns (bool)
```
### getPixTargetString
_List of valid Bacen signature addresses_
#### Parameters
| Name | Type | Description |
| ---- | ------- | ----------- |
| \_0 | uint256 | undefined |
#### Returns
| Name | Type | Description |
| ---- | ---- | ----------- |
| \_0 | bool | undefined |
### withdraw
```solidity
function getPixTargetString(address seller, contract ERC20 token) public view returns (string pixTarget)
function withdraw(uint256 depositID, bytes32[] expiredLocks) external nonpayable
```
### getBalances
Seller's expired deposit fund sweeper.
_A seller may use this method to recover tokens from expired deposits.Function sighash: 0x36317972._
#### Parameters
| Name | Type | Description |
| ------------ | --------- | ----------- |
| depositID | uint256 | undefined |
| expiredLocks | bytes32[] | undefined |
### withdrawBalance
```solidity
function getBalances(address[] sellers, contract ERC20 token) external view returns (uint256[])
function withdrawBalance() external nonpayable
```
### getLocksStatus
_Contract's underlying balance withdraw method.Function sighash: 0x5fd8c710._
## Events
### AllowedERC20Updated
```solidity
function getLocksStatus(uint256[] ids) external view returns (uint256[], enum DataTypes.LockStatus[])
event AllowedERC20Updated(address indexed token, bool indexed state)
```
External getter that returns the status of a lockIDs array.
Call will not revert if provided with an empty array as parameter.
#### Parameters
_Function sighash: 0x49ef8448_
| Name | Type | Description |
| --------------- | ------- | ----------- |
| token `indexed` | address | undefined |
| state `indexed` | bool | undefined |
### DepositAdded
```solidity
event DepositAdded(address indexed seller, uint256 depositID, address token, uint256 amount)
```
███ Events ████████████████████████████████████████████████████████████
#### Parameters
| Name | Type | Description |
| ---------------- | ------- | ----------- |
| seller `indexed` | address | undefined |
| depositID | uint256 | undefined |
| token | address | undefined |
| amount | uint256 | undefined |
### DepositClosed
```solidity
event DepositClosed(address indexed seller, uint256 depositID)
```
#### Parameters
| Name | Type | Description |
| ---------------- | ------- | ----------- |
| seller `indexed` | address | undefined |
| depositID | uint256 | undefined |
### DepositWithdrawn
```solidity
event DepositWithdrawn(address indexed seller, uint256 depositID, uint256 amount)
```
#### Parameters
| Name | Type | Description |
| ---------------- | ------- | ----------- |
| seller `indexed` | address | undefined |
| depositID | uint256 | undefined |
| amount | uint256 | undefined |
### FundsWithdrawn
```solidity
event FundsWithdrawn(address owner, uint256 amount)
```
#### Parameters
| Name | Type | Description |
| ------ | ------- | ----------- |
| owner | address | undefined |
| amount | uint256 | undefined |
### LockAdded
```solidity
event LockAdded(address indexed buyer, bytes32 indexed lockID, uint256 depositID, uint256 amount)
```
#### Parameters
| Name | Type | Description |
| ---------------- | ------- | ----------- |
| buyer `indexed` | address | undefined |
| lockID `indexed` | bytes32 | undefined |
| depositID | uint256 | undefined |
| amount | uint256 | undefined |
### LockBlocksUpdated
```solidity
event LockBlocksUpdated(uint256 blocks)
```
#### Parameters
| Name | Type | Description |
| ------ | ------- | ----------- |
| blocks | uint256 | undefined |
### LockReleased
```solidity
event LockReleased(address indexed buyer, bytes32 lockId)
```
#### Parameters
| Name | Type | Description |
| --------------- | ------- | ----------- |
| buyer `indexed` | address | undefined |
| lockId | bytes32 | undefined |
### LockReturned
```solidity
event LockReturned(address indexed buyer, bytes32 lockId)
```
#### Parameters
| Name | Type | Description |
| --------------- | ------- | ----------- |
| buyer `indexed` | address | undefined |
| lockId | bytes32 | undefined |
### OwnerUpdated
```solidity
event OwnerUpdated(address indexed user, address indexed newOwner)
```
#### Parameters
| Name | Type | Description |
| ------------------ | ------- | ----------- |
| user `indexed` | address | undefined |
| newOwner `indexed` | address | undefined |
### ReputationUpdated
```solidity
event ReputationUpdated(address reputation)
```
#### Parameters
| Name | Type | Description |
| ---------- | ------- | ----------- |
| reputation | address | undefined |
### ValidSignersUpdated
```solidity
event ValidSignersUpdated(address[] signers)
```
#### Parameters
| Name | Type | Description |
| ------- | --------- | ----------- |
| signers | address[] | undefined |
## Errors
### AddressDenied
```solidity
error AddressDenied()
```
_Address doesn't exist in a MerkleTree.Address not allowed as relayer.0x3b8474be_
### AlreadyReleased
```solidity
error AlreadyReleased()
```
_Lock already released or returned.0x63b4904e_
### AmountNotAllowed
```solidity
error AmountNotAllowed()
```
_Wished amount to be locked exceeds the limit allowed.0x1c18f846_
### DepositAlreadyExists
```solidity
error DepositAlreadyExists()
```
_Deposit already exist and it is still valid.0xc44bd765_
### InvalidDeposit
```solidity
error InvalidDeposit()
```
_Deposit not valid anymore.0xb2e532de_
### InvalidSigner
```solidity
error InvalidSigner()
```
_Signer is not a valid signer.0x815e1d64_
### LengthMismatch
```solidity
error LengthMismatch()
```
_Arrays' length don't match.0xff633a38_
### LoopOverflow
```solidity
error LoopOverflow()
```
_Loop bounds have overflowed.0xdfb035c9_
### NoTokens
```solidity
error NoTokens()
```
_No tokens array provided as argument.0xdf957883_
### NotEnoughTokens
```solidity
error NotEnoughTokens()
```
_Not enough token remaining on deposit.0x22bbb43c_
### NotExpired
```solidity
error NotExpired()
```
_Lock not expired or already released.Another lock with same ID is not expired yet.0xd0404f85_
### OnlySeller
```solidity
error OnlySeller()
```
_Only seller could call this function.`msg.sender` and the seller differ.0x85d1f726_
### Reentrancy
```solidity
error Reentrancy()
```
### TokenDenied
```solidity
error TokenDenied()
```
_Token address not allowed to be deposited.0x1578328e_
### TxAlreadyUsed
```solidity
error TxAlreadyUsed()
```
_Transaction already used to unlock payment.0xf490a6ea_

View File

@@ -1,6 +1,7 @@
import "@nomicfoundation/hardhat-chai-matchers";
import "@nomicfoundation/hardhat-toolbox";
import { config as dotenvConfig } from "dotenv";
import "hardhat-tracer";
import { HardhatUserConfig } from "hardhat/config";
import { NetworkUserConfig } from "hardhat/types";
import "hardhat-contract-sizer";
@@ -14,6 +15,14 @@ if (!mnemonic) {
throw new Error("Please set your MNEMONIC in a .env file");
}
const infuraApiKey: string | undefined =
process.env.INFURA_API_KEY;
if (!infuraApiKey) {
throw new Error(
"Please set your INFURA_API_KEY in a .env file",
);
}
const alchemyApiKey: string | undefined =
process.env.ALCHEMY_API_KEY;
if (!alchemyApiKey) {
@@ -26,16 +35,33 @@ const chainIds = {
// "{INSERT_NAME}": {INSERT_ID},
hardhat: 31337,
mainnet: 1,
"eth-sepolia": 11155111,
sepolia: 11155111,
goerli: 5,
"polygon-mumbai": 80001,
rootstock:30,
"rootstock-testnet":31,
rsktestnet:31,
};
function getChainConfig(
chain: keyof typeof chainIds,
): NetworkUserConfig {
let jsonRpcUrl = "https://" + chain + ".g.alchemy.com/v2/" + alchemyApiKey;
let jsonRpcUrl: string;
switch (chain) {
case "polygon-mumbai":
jsonRpcUrl =
"https://polygon-mumbai.g.alchemy.com/v2/" +
alchemyApiKey;
break;
case "rsktestnet":
jsonRpcUrl = "https://public-node.testnet.rsk.co/";
break;
case "rootstock":
jsonRpcUrl = "https://public-node.rsk.co/"
break;
default:
jsonRpcUrl =
"https://" + chain + ".infura.io/v3/" + infuraApiKey;
}
return {
// Comment out for default hardhat account settings
accounts: {
@@ -64,7 +90,6 @@ const config: HardhatUserConfig = {
process.env.REPORT_GAS &&
process.env.REPORT_GAS != "false"
),
offline: true,
showTimeSpent: true,
showMethodSig: true,
token: "ETH",
@@ -84,10 +109,11 @@ const config: HardhatUserConfig = {
},
// network: getChainConfig("{INSERT_NAME}"),
mainnet: getChainConfig("mainnet"),
sepolia: getChainConfig("eth-sepolia"),
mumbai: getChainConfig("polygon-mumbai"),
goerli: getChainConfig("goerli"),
sepolia: getChainConfig("sepolia"),
"polygon-mumbai": getChainConfig("polygon-mumbai"),
rootstock: getChainConfig("rootstock"),
rsktestnet: getChainConfig("rootstock-testnet"),
rsktestnet: getChainConfig("rsktestnet"),
},
paths: {
artifacts: "./artifacts",
@@ -96,10 +122,10 @@ const config: HardhatUserConfig = {
tests: "./test",
},
solidity: {
version: "0.8.28",
version: "0.8.19",
settings: {
viaIR: true,
evmVersion: "cancun",
evmVersion: "paris",
optimizer: {
enabled: true,
runs: 20_000,
@@ -119,7 +145,7 @@ const config: HardhatUserConfig = {
},
typechain: {
outDir: "src/types",
target: "ethers-v6",
target: "ethers-v5",
},
docgen: {
pages: "files",

View File

@@ -9,9 +9,10 @@
"url": "https://github.com/doiim/p2pix-smart-contracts/issues"
},
"scripts": {
"clean": "hardhat clean",
"compile": "hardhat compile",
"typechain": "hardhat typechain",
"clean": "shx rm -rf ./artifacts ./cache ./coverage ./src/types ./coverage.json && yarn typechain",
"commit": "git-cz",
"compile": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile",
"typechain": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat typechain",
"test": "hardhat test",
"deploy1:localhost": "hardhat run scripts/1-deploy-mockToken.ts --network localhost",
"deploy2:localhost": "hardhat run scripts/2-deploy-p2pix.ts --network localhost",
@@ -23,49 +24,71 @@
"lint": "yarn lint:sol && yarn lint:ts && yarn prettier:check",
"lint:sol": "solhint --config ./.solhint.json --max-warnings 0 \"contracts/**/*.sol\"",
"lint:ts": "eslint --config ./.eslintrc.yaml --ignore-path ./.eslintignore --ext .js,.ts .",
"_postinstall": "husky install",
"postpublish": "pinst --enable",
"prepublishOnly": "pinst --disable",
"prettier": "prettier --config ./.prettierrc.yaml --write \"**/*.{js,json,md,sol,ts,yaml,yml}\"",
"prettier:check": "prettier --check --config ./.prettierrc.yaml \"**/*.{js,json,md,sol,ts,yaml,yml}\""
},
"devDependencies": {
"@ethersproject/abi": "^5.8.0",
"@ethersproject/providers": "^5.8.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.1.0",
"@nomicfoundation/hardhat-ethers": "^3.1.0",
"@nomicfoundation/hardhat-ignition": "^0.15.13",
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.14",
"@nomicfoundation/hardhat-network-helpers": "^1.1.0",
"@nomicfoundation/hardhat-toolbox": "^6.1.0",
"@nomicfoundation/hardhat-verify": "^2.1.0",
"@nomicfoundation/hardhat-viem": "^2.1.0",
"@nomicfoundation/ignition-core": "^0.15.13",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^4.3.20",
"@types/mocha": "^10.0.10",
"@types/node": "^24.1.0",
"chai": "4.5.0",
"dotenv": "^16.6.1",
"eslint": "^9.32.0",
"eslint-config-prettier": "^10.1.8",
"ethers": "^6.15.0",
"hardhat": "^2.26.1",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-gas-reporter": "^2.3.0",
"@commitlint/cli": "^17.2.0",
"@commitlint/config-conventional": "^17.2.0",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.4",
"@nomicfoundation/hardhat-network-helpers": "1.0.6",
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.2.1",
"@nomiclabs/hardhat-etherscan": "^3.1.2",
"@trivago/prettier-plugin-sort-imports": "^3.4.0",
"@typechain/ethers-v5": "^10.1.1",
"@typechain/hardhat": "^6.1.4",
"@types/chai": "^4.3.3",
"@types/fs-extra": "^9.0.13",
"@types/mocha": "^9.1.1",
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.42.0",
"@typescript-eslint/parser": "^5.42.0",
"chai": "^4.3.6",
"chalk": "4.x",
"commitizen": "^4.2.5",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.3.0",
"dotenv": "^16.0.3",
"eslint": "^8.26.0",
"eslint-config-prettier": "^8.5.0",
"ethers": "^5.7.2",
"fs-extra": "^10.1.0",
"hardhat": "^2.12.2",
"hardhat-contract-sizer": "^2.8.0",
"hardhat-gas-reporter": "^1.0.9",
"hardhat-tracer": "beta",
"husky": "^8.0.1",
"keccak256": "^1.0.6",
"lint-staged": "^13.0.3",
"lodash": "^4.17.21",
"merkletreejs": "^0.5.2",
"mocha": "^10.8.2",
"solidity-coverage": "^0.8.16",
"merkletreejs": "^0.2.32",
"mocha": "^10.1.0",
"pinst": "^3.0.0",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0-rc.1",
"shx": "^0.3.4",
"solhint": "^3.3.7",
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "^0.8.2",
"solidity-docgen": "^0.6.0-beta.36",
"ts-node": "^10.9.2",
"typechain": "^8.3.2",
"typescript": "^5.8.3",
"viem": "^2.33.1"
"ts-generator": "^0.1.1",
"ts-node": "^10.9.1",
"typechain": "^8.1.1",
"typescript": "^4.8.4"
},
"files": [
"/contracts"
],
"packageManager": "yarn@4.9.2",
"packageManager": "yarn@3.2.1",
"publishConfig": {
"access": "public"
}

View File

@@ -1,11 +1,14 @@
import "@nomicfoundation/hardhat-ethers";
import "@nomiclabs/hardhat-ethers";
import "@nomiclabs/hardhat-etherscan";
import { BigNumber } from "ethers";
import * as fs from "fs";
import { ethers, network } from "hardhat";
import hre from "hardhat";
import { Deploys } from "../test/utils/interfaces";
let deploysJson: Deploys;
const supply: BigInt = ethers.parseEther("20000000");
const supply: BigNumber = ethers.utils.parseEther("20000000");
const main = async () => {
try {
@@ -22,11 +25,15 @@ const main = async () => {
const [deployer] = await ethers.getSigners();
console.log(`Deploying contracts with ${deployer.address}`);
let erc20 = await ethers.deployContract("MockToken", [supply]);
erc20 = await erc20.waitForDeployment();
const ERC20Factory = await ethers.getContractFactory(
"MockToken",
);
const erc20 = await ERC20Factory.deploy(supply);
await erc20.deployed();
deploysJson.token = await erc20.getAddress();
console.log("🚀 Mock Token Deployed:", await erc20.getAddress());
deploysJson.token = erc20.address;
console.log("🚀 Mock Token Deployed:", erc20.address);
await erc20.deployTransaction.wait(6);
fs.writeFileSync(
`./deploys/${network.name}.json`,

View File

@@ -1,6 +1,8 @@
import "@nomicfoundation/hardhat-ethers";
import "@nomiclabs/hardhat-ethers";
import "@nomiclabs/hardhat-etherscan";
import * as fs from "fs";
import { ethers, network } from "hardhat";
import hre from "hardhat";
import { Deploys } from "../test/utils/interfaces";
@@ -21,24 +23,32 @@ const main = async () => {
const [deployer] = await ethers.getSigners();
console.log(`Deploying contracts with ${deployer.address}`);
let reputation = await ethers.deployContract("Reputation");
let multicall = await ethers.deployContract("Multicall");
let p2pix = await ethers.deployContract("P2PIX", [
const Reputation = await ethers.getContractFactory(
"Reputation",
);
const Multicall = await ethers.getContractFactory(
"Multicall",
);
const reputation = await Reputation.deploy();
await reputation.deployed();
const mutlicall = await Multicall.deploy();
await mutlicall.deployed();
const P2PIX = await ethers.getContractFactory("P2PIX");
const p2pix = await P2PIX.deploy(
10,
deploysJson.signers,
reputation.target,
reputation.address,
[deploysJson.token],
[true],
]);
);
await p2pix.deployed();
reputation = await reputation.waitForDeployment();
multicall = await multicall.waitForDeployment();
p2pix = await p2pix.waitForDeployment();
deploysJson.p2pix = await p2pix.getAddress();
console.log("🚀 P2PIX Deployed:", await p2pix.getAddress());
console.log("🌠 Reputation Deployed:", await reputation.getAddress());
console.log("🛰 Multicall Deployed:", await multicall.getAddress());
deploysJson.p2pix = p2pix.address;
console.log("🚀 P2PIX Deployed:", p2pix.address);
console.log("🌠 Reputation Deployed:", reputation.address);
console.log("🛰 Multicall Deployed:", mutlicall.address);
await p2pix.deployTransaction.wait(6);
fs.writeFileSync(
`./deploys/${network.name}.json`,

View File

@@ -1,6 +1,6 @@
import "@nomicfoundation/hardhat-chai-matchers";
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { ethers, network } from "hardhat";
@@ -15,7 +15,7 @@ describe("Reputation", () => {
before("Set signers and reset network", async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[owner] = await ethers.getSigners();
[owner] = await (ethers as any).getSigners();
await network.provider.send("hardhat_reset");
});
@@ -60,7 +60,7 @@ describe("Reputation", () => {
},
{
x: Number.MAX_SAFE_INTEGER,
expected: curve(Number.MAX_SAFE_INTEGER),
shouldRevert: "overflow",
},
{
x: Number.POSITIVE_INFINITY,

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { Signer } from "ethers";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { BigNumber, Signer } from "ethers";
import { ethers } from "hardhat";
import keccak256 from "keccak256";
import { MerkleTree } from "merkletreejs";
@@ -14,7 +14,30 @@ import {
import { Call, RepFixture, P2PixAndReputation, DepositArgs, LockArgs, ReleaseArgs } from "./interfaces";
// exported constants
export const createDepositArgs = (pixTarget: string, allowlistRoot: string, token: string, amount: BigNumber, valid:boolean): DepositArgs => ({
pixTarget,
allowlistRoot,
token,
amount,
valid,
});
export const createLockArgs = (seller: string, token: string, amount: BigNumber, merkleProof: string[], expiredLocks: BigNumber[]): LockArgs => ({
seller,
token,
amount,
merkleProof,
expiredLocks,
});
export const createReleaseArgs = (lockID: BigNumber, pixTimestamp: string, signature: string): ReleaseArgs => ({
lockID,
pixTimestamp,
signature,
});
export const getSignerAddrs = (
amount: number,
addrs: SignerWithAddress[],
@@ -22,16 +45,16 @@ export const getSignerAddrs = (
return addrs.slice(0, amount).map(({ address }) => address);
};
export const getBnFrom = (nums: number[]): BigInt[] => {
const bns = nums.map(num => BigInt(num));
export const getBnFrom = (nums: number[]): BigNumber[] => {
const bns = nums.map(num => ethers.BigNumber.from(num));
return bns;
};
export const getLockData = (
addr: string,
locks: BigInt[][],
locks: BigNumber[][],
): Call[] => {
const iface = new ethers.Interface(
const iface = new ethers.utils.Interface(
P2PIX__factory.abi,
);
return locks.map(lock => ({
@@ -71,8 +94,13 @@ export const curve = (x: number): number => {
// exported async functions
export async function repFixture(): Promise<RepFixture> {
const reputation = await ethers.deployContract("Reputation");
return { reputation: await reputation.waitForDeployment() };
const Reputation = await ethers.getContractFactory(
"Reputation",
);
const reputation =
(await Reputation.deploy()) as Reputation;
return { reputation };
}
export async function p2pixFixture(): Promise<P2PixAndReputation> {
@@ -81,21 +109,30 @@ export async function p2pixFixture(): Promise<P2PixAndReputation> {
await ethers.getSigners(),
);
const reputation = await ethers.deployContract("Reputation");
const Reputation = await ethers.getContractFactory(
"Reputation",
);
const reputation =
(await Reputation.deploy()) as Reputation;
const erc20 = await ethers.deployContract("MockToken", [
ethers.parseEther("20000000") // 20M
]) as MockToken;
const ERC20 = await ethers.getContractFactory("MockToken");
const erc20 = (await ERC20.deploy(
ethers.utils.parseEther("20000000"), // 20M
)) as MockToken;
const p2pix = await ethers.deployContract("P2PIX", [
const P2PIX = await ethers.getContractFactory("P2PIX");
const p2pix = (await P2PIX.deploy(
10,
validSigners,
reputation.target,
[erc20.target],
reputation.address,
[erc20.address],
[true],
]);
)) as P2PIX;
const multicall = await ethers.deployContract("Multicall");
const Multicall = await ethers.getContractFactory(
"Multicall",
);
const multicall = (await Multicall.deploy()) as Multicall;
const signers = await ethers.getSigners();
const whitelisted = signers.slice(0, 2);
@@ -111,10 +148,10 @@ export async function p2pixFixture(): Promise<P2PixAndReputation> {
);
return {
multicall: await multicall.waitForDeployment(),
reputation: await reputation.waitForDeployment(),
erc20: await erc20.waitForDeployment(),
p2pix: await p2pix.waitForDeployment(),
multicall,
reputation,
erc20,
p2pix,
merkleRoot,
proof,
};

View File

@@ -1,3 +1,5 @@
import { BigNumber } from "ethers";
import {
MockToken,
Multicall,
@@ -17,29 +19,29 @@ export interface DepositArgs {
pixTarget: string;
allowlistRoot: string;
token: string;
amount: BigInt;
amount: BigNumber;
valid: boolean;
}
export interface LockArgs {
seller: string;
token: string;
amount: BigInt;
amount: BigNumber;
merkleProof: string[];
expiredLocks: BigInt[];
expiredLocks: BigNumber[];
}
export interface ReleaseArgs {
lockID: BigInt;
lockID: BigNumber;
pixTimestamp: string;
signature: string;
}
export interface Lock {
counter: BigInt;
expirationBlock: BigInt;
counter: BigNumber;
expirationBlock: BigNumber;
pixTarget: string;
amount: BigInt;
amount: BigNumber;
token: string;
buyerAddress: string;
seller: string;

11533
yarn.lock

File diff suppressed because it is too large Load Diff