Compare commits

..

2 Commits

Author SHA1 Message Date
hueso
811d5344a3 Partial hardhat -> viem migration for tests.
Typescript updated to v5.
Notably all calls to p2pix.callStatic.getStr() were replaced by viem.stringToHex() due to bug in ethers (https://github.com/ethers-io/ethers.js/issues/4965)
Full migration to viem might not be possible currently due to hard-chai-matchers incompatibility:
> The hardhat-chai-matchers plugin is designed to work with hardhat-ethers. Attempting to use it in conjunction with hardhat-viem results in compatibility issues.
https://hardhat.org/hardhat-chai-matchers/docs/overview
2025-06-11 11:55:24 -03:00
hueso
4f1f8d6025 sepolia deployment 2024-07-18 17:59:44 -03:00
11 changed files with 3129 additions and 5425 deletions

View File

@ -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

@ -13,7 +13,6 @@ library DataTypes {
ERC20 token;
address buyerAddress;
address seller;
bool bond;
}
// prettier-ignore

View File

@ -135,8 +135,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 +154,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.
if (merkleProof.length != 0) {
_merkleVerify( merkleProof, sellerAllowList(seller), _msgSender());
} else if ( amount > REPUTATION_LOWERBOUND && msg.sender == _msgSender() ) {
@ -186,8 +178,7 @@ contract P2PIX is BaseUtils {
amount,
token,
_msgSender(),
seller,
bond
seller
);
_addLock(bal, l);
@ -246,7 +237,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 +266,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;

8
deploys/sepolia.json Normal file
View File

@ -0,0 +1,8 @@
{
"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

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

View File

@ -67,7 +67,7 @@ _Function sighash: 0x6d82d9e0_
### lock
```solidity
function lock(address seller, contract ERC20 token, uint80 amount, bytes32[] merkleProof, uint256[] expiredLocks, bool bond) public returns (uint256 lockID)
function lock(address seller, contract ERC20 token, uint80 amount, bytes32[] merkleProof, uint256[] expiredLocks) public returns (uint256 lockID)
```
Public method designed to lock an remaining amount of
@ -78,7 +78,7 @@ 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
There can only exist a lock per each `_amount` partitioned
from the total `remaining` value.
Locks can only be performed in valid orders.
@ -93,7 +93,6 @@ _Function sighash: 0xdc43221c_
| amount | uint80 | The deposit's remaining amount wished to be locked. |
| 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 | |
#### Return Values

View File

@ -1,7 +1,6 @@
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";
@ -56,8 +55,11 @@ function getChainConfig(
jsonRpcUrl = "https://public-node.testnet.rsk.co/";
break;
case "rootstock":
jsonRpcUrl = "https://public-node.rsk.co/"
jsonRpcUrl = "https://public-node.rsk.co/";
break;
case "sepolia":
jsonRpcUrl = "https://rpc.sepolia.online";
break
default:
jsonRpcUrl =
"https://" + chain + ".infura.io/v3/" + infuraApiKey;

View File

@ -41,7 +41,8 @@
"@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",
"@nomicfoundation/hardhat-viem": "^2.0.6",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-etherscan": "^3.1.2",
"@trivago/prettier-plugin-sort-imports": "^3.4.0",
"@typechain/ethers-v5": "^10.1.1",
@ -65,14 +66,12 @@
"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.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",
@ -83,7 +82,8 @@
"ts-generator": "^0.1.1",
"ts-node": "^10.9.1",
"typechain": "^8.1.1",
"typescript": "^4.8.4"
"typescript": "^5",
"viem": "^2.23.14"
},
"files": [
"/contracts"

View File

@ -6,8 +6,6 @@ import {
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import {
BigNumber,
BytesLike,
ContractReceipt,
ContractTransaction,
Wallet,
@ -38,6 +36,10 @@ import {
p2pixFixture,
randomSigners,
} from "./utils/fixtures";
import {
parseEther,
stringToHex,
} from "viem";
describe("P2PIX", () => {
type WalletWithAddress = Wallet & SignerWithAddress;
@ -60,11 +62,10 @@ describe("P2PIX", () => {
let merkleRoot: string; // MerkleRoot from seller's allowlist
let proof: string[]; // Owner's proof as whitelisted address
const fundAmount: BigNumber =
ethers.utils.parseEther("10000");
const price: BigNumber = ethers.utils.parseEther("100");
const fundAmount: BigInt = parseEther("10000");
const price: BigInt = parseEther("100");
const zero = ethers.constants.AddressZero;
const zero = '0x0000000000000000000000000000000000000000';
before("Set signers and reset network", async () => {
[owner, acc01, acc02, acc03] =
@ -171,7 +172,7 @@ describe("P2PIX", () => {
await expect(p2pix.withdrawBalance())
.to.changeEtherBalances(
[owner.address, p2pix.address],
[price, price.mul(-1)],
[price, price * -1n],
)
.and.to.emit(p2pix, "FundsWithdrawn")
.withArgs(owner.address, price);
@ -337,7 +338,7 @@ describe("P2PIX", () => {
const root = ethers.utils.keccak256(
ethers.utils.toUtf8Bytes("root"),
);
const tx = p2pix.deposit(pTarget, root, erc20.address, ethers.utils.parseEther("100000001"), true);
const tx = p2pix.deposit(pTarget, root, erc20.address, parseEther("100000001"), true);
await expect(tx).to.be.revertedWithCustomError(
p2pix,
@ -384,10 +385,10 @@ describe("P2PIX", () => {
await expect(tx).to.changeTokenBalances(
erc20,
[owner.address, p2pix.address],
[price.mul(-1), price],
[price * -1n, price],
);
expect(storage).to.eq(price);
expect(pixTarget).to.eq(await p2pix.callStatic.getStr(pTarget));
expect(pixTarget).to.eq(stringToHex(pTarget,{size:32}));
expect(valid).to.eq(true);
expect(allowList).to.eq(root);
expect(balances[0]).to.eq(price);
@ -415,10 +416,10 @@ describe("P2PIX", () => {
ethers.utils.toUtf8Bytes("root"),
);
const nullRoot = ethers.constants.HashZero;
const price2 = price.mul(ethers.BigNumber.from(2));
const price3 = price.mul(ethers.BigNumber.from(3));
const price4 = price.mul(ethers.BigNumber.from(4));
const prices: BigNumber[] = [
const price2 = price * 2n;
const price3 = price * 3n;
const price4 = price * 4n;
const prices: BigInt[] = [
price,
price2,
price3,
@ -564,7 +565,7 @@ describe("P2PIX", () => {
const tx = transactions[i];
const addr = addresses[i];
const depositPrice = depositPrices[i];
const amount = ethers.utils.parseEther("100").mul(i+1).mul(-1).toBigInt();
const amount = parseEther("100") * BigInt(i+1) * -1n;
await expect(tx)
.to.emit(p2pix, "DepositAdded")
@ -582,22 +583,22 @@ describe("P2PIX", () => {
expect(prices[3]).to.eq(balances[3]);
expect(storage1).to.eq(price);
expect(pixTarget1).to.eq(await p2pix.callStatic.getStr(pTarget));
expect(pixTarget1).to.eq(stringToHex(pTarget,{size:32}));
expect(valid1).to.eq(true);
expect(allowList1).to.eq(root);
expect(storage2).to.eq(price2);
expect(pixTarget2).to.eq(await p2pix.callStatic.getStr(pTarget2));
expect(pixTarget2).to.eq(stringToHex(pTarget2,{size:32}));
expect(valid2).to.eq(false);
expect(allowList2).to.eq(nullRoot);
expect(storage3).to.eq(price3);
expect(pixTarget3).to.eq(await p2pix.callStatic.getStr(pTarget3));
expect(pixTarget3).to.eq(stringToHex(pTarget3,{size:32}));
expect(valid3).to.eq(true);
expect(allowList3).to.eq(root);
expect(storage4).to.eq(price4);
expect(pixTarget4).to.eq(await p2pix.callStatic.getStr(pTarget));
expect(pixTarget4).to.eq(stringToHex(pTarget,{size:32}));
expect(valid4).to.eq(false);
expect(allowList4).to.eq(nullRoot);
});
@ -622,7 +623,6 @@ describe("P2PIX", () => {
price,
[],
[],
false,
);
const fail2 = p2pix.lock(
zero,
@ -630,7 +630,6 @@ describe("P2PIX", () => {
price,
[],
[],
false,
);
await expect(fail).to.be.revertedWithCustomError(
@ -657,10 +656,9 @@ describe("P2PIX", () => {
.lock(
owner.address,
erc20.address,
price.mul(ethers.BigNumber.from(2)),
price * 2n,
[],
[],
false,
);
await expect(fail).to.be.revertedWithCustomError(
@ -683,10 +681,9 @@ describe("P2PIX", () => {
.lock(
owner.address,
erc20.address,
ethers.BigNumber.from(1000),
1000n,
[ethers.utils.keccak256(ethers.utils.toUtf8Bytes("wrong"))],
[],
false,
);
await expect(fail).to.be.revertedWithCustomError(
@ -697,13 +694,13 @@ describe("P2PIX", () => {
it("should revert if msg.sender does not have enough credit in his spend limit", async () => {
await erc20.approve(
p2pix.address,
price.mul(3),
price * 3n,
);
await p2pix.deposit(
"1",
merkleRoot,
erc20.address,
price.mul(3),
price * 3n,
true,
);
const fail = p2pix
@ -711,10 +708,9 @@ describe("P2PIX", () => {
.lock(
owner.address,
erc20.address,
price.mul(2),
price * 2n,
[],
[],
false,
);
await expect(fail).to.be.revertedWithCustomError(
@ -722,42 +718,6 @@ describe("P2PIX", () => {
P2PixErrors.AmountNotAllowed,
);
});
it("should override spend limit if buyer pays the bond", async () => {
await erc20.approve(
p2pix.address,
price.mul(3),
);
await p2pix.deposit(
"1",
merkleRoot,
erc20.address,
price.mul(3),
true,
);
await erc20
.transfer(
acc02.address,
price,
);
await erc20
.connect(acc02)
.approve(
p2pix.address,
price.mul(30000),
);
const bond = p2pix
.connect(acc02)
.lock(
owner.address,
erc20.address,
price.mul(2),
[],
[],
true,
);
await expect(bond).to.be.ok;
});
it("should create a lock, update storage and emit events via the allowlist path", async () => {
const target = "333";
await erc20.approve(p2pix.address, price);
@ -776,7 +736,6 @@ describe("P2PIX", () => {
price,
proof,
[],
false,
);
const storage: Lock = await p2pix.callStatic.mapLocks(
1,
@ -798,7 +757,7 @@ describe("P2PIX", () => {
expect(storage.counter).to.eq(1);
expect(storage.amount).to.eq(price);
expect(storage.expirationBlock).to.eq(expiration);
expect(storage.pixTarget).to.eq(await p2pix.callStatic.getStr(target));
expect(storage.pixTarget).to.eq(stringToHex(target,{size:32}));
expect(storage.buyerAddress).to.eq(acc01.address);
expect(storage.token).to.eq(erc20.address);
});
@ -821,7 +780,6 @@ describe("P2PIX", () => {
price,
[],
[],
false,
);
const storage: Lock = await p2pix.callStatic.mapLocks(
1,
@ -842,7 +800,7 @@ describe("P2PIX", () => {
expect(storage.counter).to.eq(1);
expect(storage.amount).to.eq(price);
expect(storage.expirationBlock).to.eq(expiration);
expect(storage.pixTarget).to.eq(await p2pix.callStatic.getStr(target));
expect(storage.pixTarget).to.eq(stringToHex(target,{size:32}));
expect(storage.buyerAddress).to.eq(acc01.address);
expect(storage.token).to.eq(erc20.address);
@ -852,14 +810,12 @@ describe("P2PIX", () => {
});
it("should create a lock, update storage and emit events via the reputation path 2", async () => {
const root = ethers.constants.HashZero;
const newPrice = price
.mul(ethers.constants.Two)
.add(ethers.constants.One);
const newPrice = price * 2n + 1n;
const endtoendID = ethers.constants.HashZero;
const target = "101";
const messageToSign = ethers.utils.solidityKeccak256(
["bytes32", "uint80", "bytes32"],
[await p2pix.callStatic.getStr(target), price, endtoendID],
[stringToHex(target, { size: 32 }), price, endtoendID],
);
const messageHashBytes =
ethers.utils.arrayify(messageToSign);
@ -883,7 +839,6 @@ describe("P2PIX", () => {
price,
[],
[],
false,
);
await p2pix
.connect(acc01)
@ -897,10 +852,9 @@ describe("P2PIX", () => {
.lock(
owner.address,
erc20.address,
price.add(ethers.constants.One),
price + 1n,
[],
[],
false,
);
const storage: Lock = await p2pix.callStatic.mapLocks(
2,
@ -920,10 +874,10 @@ describe("P2PIX", () => {
expect(storage.seller).to.eq(owner.address);
expect(storage.counter).to.eq(2);
expect(storage.amount).to.eq(
price.add(ethers.constants.One),
price+1n,
);
expect(storage.expirationBlock).to.eq(expiration);
expect(storage.pixTarget).to.eq(await p2pix.callStatic.getStr(target));
expect(storage.pixTarget).to.eq(stringToHex(target,{size:32}));
expect(storage.buyerAddress).to.eq(acc01.address);
expect(storage.token).to.eq(erc20.address);
@ -933,8 +887,8 @@ describe("P2PIX", () => {
});
// edge case test
it("should create multiple locks", async () => {
const newPrice = price.div(ethers.BigNumber.from(2));
const target = ethers.BigNumber.from(101).toString();
const newPrice = price / 2n;
const target = BigInt(101).toString();
await erc20.approve(p2pix.address, price);
await p2pix.deposit(
target,
@ -951,7 +905,6 @@ describe("P2PIX", () => {
newPrice,
proof,
[],
false,
);
const storage1: Lock = await p2pix.callStatic.mapLocks(
1,
@ -965,10 +918,9 @@ describe("P2PIX", () => {
.lock(
owner.address,
erc20.address,
ethers.BigNumber.from(100),
BigInt(100),
[],
[],
false,
);
const storage2: Lock = await p2pix.callStatic.mapLocks(
2,
@ -982,10 +934,9 @@ describe("P2PIX", () => {
.lock(
owner.address,
erc20.address,
ethers.BigNumber.from(100),
BigInt(100),
[],
[],
false,
);
const storage3: Lock = await p2pix.callStatic.mapLocks(
3,
@ -1004,24 +955,24 @@ describe("P2PIX", () => {
// const lockStatus4 = await p2pix.callStatic.getLocksStatus([]);
// All getLocksStatus calls were batched via the Multicall contract.
const ls1: [BigNumber[], BigNumber[]] = [
const ls1: [BigInt[], BigInt[]] = [
getBnFrom([1, 7, 7, 2, 3, 4, 5, 5, 2, 3]),
getBnFrom([1, 0, 0, 1, 1, 0, 0, 0, 1, 1]),
];
const ls2: [BigNumber[], BigNumber[]] = [
const ls2: [BigInt[], BigInt[]] = [
getBnFrom([0, 1, 2, 3]),
getBnFrom([0, 1, 1, 1]),
];
const ls3: [BigNumber[], BigNumber[]] = [
const ls3: [BigInt[], BigInt[]] = [
getBnFrom([7, 7, 333, 14, 777]),
getBnFrom([0, 0, 0, 0, 0]),
];
const ls4 = [[], []];
const batchedLocks: Array<BigNumber[]> = [
const batchedLocks: Array<BigInt[]> = [
ls1,
ls2,
ls3,
@ -1038,7 +989,7 @@ describe("P2PIX", () => {
);
const blockNumber = batchCall[0];
const result: Array<BytesLike> = batchCall[1].slice(
const result: Array<Bytes> = batchCall[1].slice(
0,
4,
);
@ -1072,7 +1023,7 @@ describe("P2PIX", () => {
expect(storage3.counter).to.eq(3);
expect(storage1.amount).to.eq(newPrice);
expect(ethers.BigNumber.from(100))
expect(BigInt(100))
.to.eq(storage2.amount)
.and.to.eq(storage3.amount);
@ -1080,7 +1031,7 @@ describe("P2PIX", () => {
expect(storage2.expirationBlock).to.eq(expiration2);
expect(storage3.expirationBlock).to.eq(expiration3);
expect(await p2pix.callStatic.getStr(target))
expect(stringToHex(target,{size:32}))
.to.eq(storage1.pixTarget)
.and.to.eq(storage2.pixTarget)
.and.to.eq(storage3.pixTarget);
@ -1118,7 +1069,7 @@ describe("P2PIX", () => {
it("should setValidState, update storage and emit events", async () => {
await erc20.approve(p2pix.address, price);
await p2pix.deposit(
ethers.BigNumber.from(10101).toString(),
BigInt(10101).toString(),
merkleRoot,
erc20.address,
price,
@ -1147,7 +1098,7 @@ describe("P2PIX", () => {
it("should cancel multiple balances", async () => {
const hashZero = ethers.constants.HashZero;
await erc20.mint([acc01.address, acc02.address], price);
const target = ethers.BigNumber.from("1").toString();
const target = BigInt(1).toString();
await erc20.approve(p2pix.address, price);
await p2pix.deposit(
target,
@ -1237,7 +1188,7 @@ describe("P2PIX", () => {
});
describe("Release", async () => {
it("should revert if lock has expired", async () => {
const target = ethers.BigNumber.from(101).toString();
const target = BigInt(101).toString();
const messageToSign = ethers.utils.solidityKeccak256(
["uint160", "uint80", "bytes32"],
[target, 100, ethers.constants.HashZero],
@ -1259,10 +1210,9 @@ describe("P2PIX", () => {
.lock(
owner.address,
erc20.address,
ethers.BigNumber.from(100),
BigInt(100),
[],
[],
false,
);
const lockID = ethers.constants.One;
await mine(13);
@ -1278,11 +1228,11 @@ describe("P2PIX", () => {
);
});
it("should revert if lock has already been released", async () => {
const target = ethers.BigNumber.from("1").toString();
const target = BigInt(1).toString();
const hashZero = ethers.constants.HashZero;
const messageToSign = ethers.utils.solidityKeccak256(
["bytes32", "uint80", "bytes32"],
[await p2pix.callStatic.getStr(target), 100, hashZero],
[stringToHex(target,{size:32}), 100, hashZero],
);
const flatSig = await acc01.signMessage(
ethers.utils.arrayify(messageToSign),
@ -1301,10 +1251,9 @@ describe("P2PIX", () => {
.lock(
owner.address,
erc20.address,
ethers.BigNumber.from(100),
BigInt(100),
[],
[],
false,
);
const lockID = ethers.constants.One;
await p2pix.release(
@ -1324,10 +1273,10 @@ describe("P2PIX", () => {
);
});
it("should revert if signed message has already been used", async () => {
const target = ethers.BigNumber.from(101).toString();
const target = BigInt(101).toString();
const messageToSign = ethers.utils.solidityKeccak256(
["bytes32", "uint80", "bytes32"],
[await p2pix.callStatic.getStr(target), 100, ethers.constants.HashZero],
[stringToHex(target,{size:32}), 100, ethers.constants.HashZero],
);
const flatSig = await owner.signMessage(
ethers.utils.arrayify(messageToSign),
@ -1346,10 +1295,9 @@ describe("P2PIX", () => {
.lock(
owner.address,
erc20.address,
ethers.BigNumber.from(100),
BigInt(100),
[],
[],
false,
);
await p2pix
@ -1364,10 +1312,9 @@ describe("P2PIX", () => {
.lock(
owner.address,
erc20.address,
ethers.BigNumber.from(100),
BigInt(100),
[],
[],
false,
);
const fail = p2pix
.connect(acc01)
@ -1383,10 +1330,10 @@ describe("P2PIX", () => {
);
});
it("should revert if ecrecovered signer is invalid", async () => {
const target = ethers.BigNumber.from(101).toString();
const target = BigInt(101).toString();
const messageToSign = ethers.utils.solidityKeccak256(
["bytes32", "uint80", "bytes32"],
[await p2pix.callStatic.getStr(target), 100, ethers.constants.HashZero],
[stringToHex(target,{size:32}), 100, ethers.constants.HashZero],
);
const flatSig = await acc03.signMessage(
ethers.utils.arrayify(messageToSign),
@ -1406,10 +1353,9 @@ describe("P2PIX", () => {
.lock(
owner.address,
erc20.address,
ethers.BigNumber.from(100),
BigInt(100),
[],
[],
false,
);
const fail = p2pix
.connect(acc01)
@ -1427,10 +1373,10 @@ describe("P2PIX", () => {
it("should release lock, update storage and emit events", async () => {
const zero = ethers.constants.Zero;
const endtoendID = ethers.constants.HashZero;
const pixTarget = ethers.BigNumber.from(101).toString();
const pixTarget = BigInt(101).toString();
const messageToSign = ethers.utils.solidityKeccak256(
["bytes32", "uint80", "bytes32"],
[await p2pix.callStatic.getStr(pixTarget), 100, endtoendID],
[stringToHex(pixTarget,{size:32}), 100, endtoendID],
);
// Note: messageToSign is a string, that is 66-bytes long, to sign the
// binary value, we must convert it to the 32 byte Array that
@ -1463,10 +1409,9 @@ describe("P2PIX", () => {
.lock(
owner.address,
erc20.address,
ethers.BigNumber.from(100),
BigInt(100),
[],
[],
false,
);
const acc01Key = await p2pix.callStatic._castAddrToKey(
acc01.address,
@ -1493,7 +1438,7 @@ describe("P2PIX", () => {
const lockStatus1 =
await p2pix.callStatic.getLocksStatus([1]);
const ls1: [BigNumber[], number[]] = [
const ls1: [BigInt[], number[]] = [
[ethers.constants.One],
[3],
];
@ -1511,10 +1456,10 @@ describe("P2PIX", () => {
];
mtcCalls.push(cd2[0]);
const mtc2 = await multicall.callStatic.mtc2(mtcCalls);
const blockNumber: BigNumber = mtc2[0];
const blockhash: BytesLike = mtc2[1];
const blockNumber: BigInt = mtc2[0];
const blockhash: Bytes = mtc2[1];
const result = mtc2.slice(2).flat(1) as Result[];
const res1: BytesLike[] = [result[1].returnData];
const res1: Bytes[] = [result[1].returnData];
const decodedLockData = res1.map(r =>
ethers.utils.defaultAbiCoder.decode(
["uint256[]", "uint8[]"],
@ -1543,10 +1488,10 @@ describe("P2PIX", () => {
storage1.amount,
);
expect(storage1.expirationBlock).to.eq(
ethers.BigNumber.from(17),
BigInt(17),
);
expect(storage1.amount).to.eq(
ethers.BigNumber.from(100),
BigInt(100),
);
expect(lockStatus1[0].toString()).to.equal(
ls1[0].toString(),
@ -1566,8 +1511,8 @@ describe("P2PIX", () => {
expect(used).to.eq(true);
expect(userRecordA).to.eq(zero);
expect(userRecord1).to.eq(zero);
expect(userRecordB).to.eq(ethers.BigNumber.from(50));
expect(userRecord2).to.eq(ethers.BigNumber.from(50));
expect(userRecordB).to.eq(BigInt(50));
expect(userRecord2).to.eq(BigInt(50));
await expect(tx).to.changeTokenBalances(
erc20,
[acc03.address, acc01.address, acc02.address ],
@ -1577,7 +1522,7 @@ describe("P2PIX", () => {
// edge case test
it("should release multiple locks", async () => {
const endtoendID = ethers.constants.HashZero;
const pixTarget = ethers.BigNumber.from(101).toString();
const pixTarget = BigInt(101).toString();
const root = ethers.constants.HashZero;
const acc01Key = await p2pix.callStatic._castAddrToKey(
acc01.address,
@ -1593,7 +1538,7 @@ describe("P2PIX", () => {
);
const messageToSign1 = ethers.utils.solidityKeccak256(
["bytes32", "uint80", "bytes32"],
[await p2pix.callStatic.getStr(pixTarget), 100, endtoendID],
[stringToHex(pixTarget,{size:32}), 100, endtoendID],
);
const flatSig1 = await owner.signMessage(
ethers.utils.arrayify(messageToSign1),
@ -1601,7 +1546,7 @@ describe("P2PIX", () => {
// const sig1 = ethers.utils.splitSignature(flatSig1);
const messageToSign2 = ethers.utils.solidityKeccak256(
["bytes32", "uint80", "bytes32"],
[await p2pix.callStatic.getStr(pixTarget), 50, endtoendID],
[stringToHex(pixTarget,{size:32}), 50, endtoendID],
);
const flatSig2 = await owner.signMessage(
ethers.utils.arrayify(messageToSign2),
@ -1609,7 +1554,7 @@ describe("P2PIX", () => {
// const sig2 = ethers.utils.splitSignature(flatSig2);
const messageToSign3 = ethers.utils.solidityKeccak256(
["bytes32", "uint80", "bytes32"],
[await p2pix.callStatic.getStr(pixTarget), 25, endtoendID],
[stringToHex(pixTarget,{size:32}), 25, endtoendID],
);
const flatSig3 = await owner.signMessage(
ethers.utils.arrayify(messageToSign3),
@ -1628,47 +1573,44 @@ describe("P2PIX", () => {
.lock(
owner.address,
erc20.address,
ethers.BigNumber.from(100),
BigInt(100),
[],
[],
false,
);
await p2pix
.connect(acc03)
.lock(
owner.address,
erc20.address,
ethers.BigNumber.from(50),
BigInt(50),
[],
[],
false,
);
await p2pix
.connect(acc03)
.lock(
owner.address,
erc20.address,
ethers.BigNumber.from(25),
BigInt(25),
[],
[],
false,
);
const lockStatus1 =
await p2pix.callStatic.getLocksStatus([1, 2, 3, 44]);
const ls1: [BigNumber[], BigNumber[]] = [
const ls1: [BigInt[], BigInt[]] = [
[
ethers.constants.One,
ethers.constants.Two,
ethers.BigNumber.from(3),
ethers.BigNumber.from(44),
BigInt(3),
BigInt(44),
],
getBnFrom([1, 1, 1, 0]),
];
const lockID = ethers.constants.One;
const lockID2 = ethers.constants.Two;
const lockID3 = ethers.BigNumber.from(3);
const lockID3 = BigInt(3);
const storage1: Lock = await p2pix.callStatic.mapLocks(
lockID,
);
@ -1722,17 +1664,17 @@ describe("P2PIX", () => {
const lockStatus2 =
await p2pix.callStatic.getLocksStatus([1, 2, 3, 44]);
const ls2: [BigNumber[], BigNumber[]] = [
const ls2: [BigInt[], BigInt[]] = [
[
ethers.constants.One,
ethers.constants.Two,
ethers.BigNumber.from(3),
ethers.BigNumber.from(44),
BigInt(3),
BigInt(44),
],
getBnFrom([3, 3, 3, 0]),
];
const batchedLocks: Array<BigNumber[]> = [
const batchedLocks: Array<BigInt[]> = [
ls1.slice(0, 1)[0],
ls2.slice(0, 1)[0],
];
@ -1804,7 +1746,7 @@ describe("P2PIX", () => {
});
describe("Unexpire Locks", async () => {
it("should revert if lock isn't expired", async () => {
const target = ethers.BigNumber.from(101).toString();
const target = BigInt(101).toString();
await erc20.approve(p2pix.address, price);
await p2pix.deposit(
target,
@ -1821,7 +1763,6 @@ describe("P2PIX", () => {
ethers.constants.One,
[],
[],
false,
);
const lockID = ethers.constants.One;
const fail = p2pix.unlockExpired([lockID]);
@ -1833,10 +1774,10 @@ describe("P2PIX", () => {
});
it("should revert if lock has already been released", async () => {
const endtoendID = ethers.constants.HashZero;
const pixTarget = ethers.BigNumber.from(101).toString();
const pixTarget = BigInt(101).toString();
const messageToSign = ethers.utils.solidityKeccak256(
["bytes32", "uint80", "bytes32"],
[await p2pix.callStatic.getStr(pixTarget), 1, endtoendID],
[stringToHex(pixTarget,{size:32}), 1, endtoendID],
);
const messageHashBytes =
ethers.utils.arrayify(messageToSign);
@ -1860,7 +1801,6 @@ describe("P2PIX", () => {
ethers.constants.One,
[],
[],
false,
);
const lockID = ethers.constants.One;
// await mine(10);
@ -1877,7 +1817,7 @@ describe("P2PIX", () => {
);
});
it("should unlock expired locks, update storage and emit events", async () => {
const target = ethers.BigNumber.from(101).toString();
const target = BigInt(101).toString();
await erc20.approve(p2pix.address, price);
await p2pix.deposit(
target,
@ -1894,18 +1834,17 @@ describe("P2PIX", () => {
ethers.constants.One,
[],
[],
false,
);
const lockID = ethers.constants.One;
await mine(11);
const lockStatus1 =
await p2pix.callStatic.getLocksStatus([11, 1, 777]);
const ls1: [BigNumber[], BigNumber[]] = [
const ls1: [BigInt[], BigInt[]] = [
[
ethers.BigNumber.from(11),
BigInt(11),
ethers.constants.One,
ethers.BigNumber.from(777),
BigInt(777),
],
getBnFrom([0, 2, 0]),
];
@ -1940,7 +1879,7 @@ describe("P2PIX", () => {
);
});
it("should unlock expired through lock function", async () => {
const target = ethers.BigNumber.from(101).toString();
const target = BigInt(101).toString();
// test method through lock fx
await erc20.approve(p2pix.address, price);
await p2pix.deposit(
@ -1958,7 +1897,6 @@ describe("P2PIX", () => {
price,
proof,
[],
false,
);
// as return values of non view functions can't be accessed
// outside the evm, we fetch the lockID from the emitted event.
@ -1995,10 +1933,9 @@ describe("P2PIX", () => {
const tx1 = await p2pix.lock(
owner.address,
erc20.address,
ethers.BigNumber.from(100),
BigInt(100),
[],
[lockID],
false
);
const remaining = await p2pix.callStatic.getBalance(
owner.address,
@ -2010,7 +1947,7 @@ describe("P2PIX", () => {
.to.emit(p2pix, "LockReturned")
.withArgs(acc01.address, lockID);
expect(remaining).to.eq(
price.sub(ethers.BigNumber.from(100)),
price - 100n,
);
});
it("should unlock expired through withdraw function", async () => {
@ -2032,7 +1969,6 @@ describe("P2PIX", () => {
price,
proof,
[],
false,
);
const lockID = ethers.constants.One;
// mine blocks to expire lock
@ -2055,7 +1991,7 @@ describe("P2PIX", () => {
describe("Seller Withdraw", async () => {
it("should revert if the wished amount is invalid", async () => {
const target = ethers.BigNumber.from(101).toString();
const target = BigInt(101).toString();
await erc20.approve(p2pix.address, price);
await p2pix.deposit(
target,
@ -2068,7 +2004,7 @@ describe("P2PIX", () => {
.connect(acc02)
.withdraw(
erc20.address,
price.mul(ethers.constants.Two),
price * 2n,
[],
);
@ -2078,10 +2014,10 @@ describe("P2PIX", () => {
);
});
it("should withdraw remaining funds from deposit, update storage and emit event", async () => {
const newPrice = price.div(ethers.constants.Two);
const newPrice = price / 2n;
await erc20.approve(p2pix.address, price);
const dep = await p2pix.deposit(
ethers.BigNumber.from(101).toString(),
BigInt(101).toString(),
merkleRoot,
erc20.address,
price,
@ -2089,7 +2025,7 @@ describe("P2PIX", () => {
);
const tx = await p2pix.withdraw(
erc20.address,
price.div(ethers.constants.Two),
price / 2n,
[],
);
@ -2098,7 +2034,7 @@ describe("P2PIX", () => {
.to.changeTokenBalance(
erc20,
owner.address,
price.mul(-1),
price * -1n,
)
.and.to.changeTokenBalance(
erc20,
@ -2110,7 +2046,7 @@ describe("P2PIX", () => {
.and.to.changeTokenBalance(
erc20,
p2pix.address,
price.div(ethers.constants.Two).mul(-1),
(price/2n) * -1n,
);
await expect(tx)

8229
yarn.lock

File diff suppressed because it is too large Load Diff