🔧 Added getLocksStatus
This commit is contained in:
parent
ce28faae9d
commit
d946c239dc
@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../build-info/6e32e8b8339868a5a7b642cfedb2d144.json"
|
||||
"buildInfo": "../../build-info/e971df088e64e6ab53f252445efd91f4.json"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../build-info/6e32e8b8339868a5a7b642cfedb2d144.json"
|
||||
"buildInfo": "../../build-info/e971df088e64e6ab53f252445efd91f4.json"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../build-info/6e32e8b8339868a5a7b642cfedb2d144.json"
|
||||
"buildInfo": "../../build-info/e971df088e64e6ab53f252445efd91f4.json"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/6e32e8b8339868a5a7b642cfedb2d144.json"
|
||||
"buildInfo": "../../../../build-info/e971df088e64e6ab53f252445efd91f4.json"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/6e32e8b8339868a5a7b642cfedb2d144.json"
|
||||
"buildInfo": "../../../../build-info/e971df088e64e6ab53f252445efd91f4.json"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/6e32e8b8339868a5a7b642cfedb2d144.json"
|
||||
"buildInfo": "../../../../build-info/e971df088e64e6ab53f252445efd91f4.json"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/6e32e8b8339868a5a7b642cfedb2d144.json"
|
||||
"buildInfo": "../../../../build-info/e971df088e64e6ab53f252445efd91f4.json"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/6e32e8b8339868a5a7b642cfedb2d144.json"
|
||||
"buildInfo": "../../../../build-info/e971df088e64e6ab53f252445efd91f4.json"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/6e32e8b8339868a5a7b642cfedb2d144.json"
|
||||
"buildInfo": "../../../../build-info/e971df088e64e6ab53f252445efd91f4.json"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/6e32e8b8339868a5a7b642cfedb2d144.json"
|
||||
"buildInfo": "../../../../build-info/e971df088e64e6ab53f252445efd91f4.json"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../build-info/6e32e8b8339868a5a7b642cfedb2d144.json"
|
||||
"buildInfo": "../../build-info/d6cb685de33a89b520e265dae6675c0e.json"
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -43,7 +43,6 @@ contract P2PIX is
|
||||
/// ███ Storage ████████████████████████████████████████████████████████████
|
||||
|
||||
IReputation public reputation;
|
||||
// Counters.Counter public depositCount;
|
||||
|
||||
/// @dev Default blocks that lock will hold tokens.
|
||||
uint256 public defaultLockBlocks;
|
||||
@ -872,6 +871,131 @@ contract P2PIX is
|
||||
return balances;
|
||||
}
|
||||
|
||||
/// @notice External getter that returns the status of a lockIDs array.
|
||||
/// @dev The `ids` array gets sorted in ascending order
|
||||
/// if a non-initialized counter value is provided as an array item.
|
||||
/// @dev The `ids` array gets sorted in descending order
|
||||
/// if all provied array items are initialized.
|
||||
/// @dev Call will not revert if provided with an empty array.
|
||||
/// @dev Function sighash: 0x49ef8448
|
||||
function getLocksStatus(uint256[] memory ids)
|
||||
external
|
||||
view
|
||||
returns(
|
||||
uint256[] memory,
|
||||
bool[] memory
|
||||
) {
|
||||
if (ids.length == 0) {
|
||||
uint256[] memory null1 =
|
||||
new uint256[](0);
|
||||
bool[] memory null2 =
|
||||
new bool[](0);
|
||||
return(null1, null2); }
|
||||
|
||||
uint256 c;
|
||||
uint256 len =
|
||||
ids.length;
|
||||
|
||||
(ids, len, c) = sort(ids);
|
||||
|
||||
if (c == 0x00) {
|
||||
bool[] memory status =
|
||||
new bool[](len);
|
||||
uint256[] memory sortedIDs =
|
||||
new uint256[](len);
|
||||
for(c; c < len;) {
|
||||
if(
|
||||
mapLocks[ids[c]].expirationBlock
|
||||
< block.number ||
|
||||
mapLocks[ids[c]].amount == 0x0) {
|
||||
sortedIDs[c] = ids[c];
|
||||
status[c] = false; ++c;
|
||||
} else {
|
||||
sortedIDs[c] = ids[c];
|
||||
status[c] = true; ++c;
|
||||
}
|
||||
}
|
||||
return(sortedIDs, status);
|
||||
}
|
||||
else if (c == len - 1) {
|
||||
uint256 p;
|
||||
bool[] memory status =
|
||||
new bool[](len - 1);
|
||||
uint256[] memory sortedIDs =
|
||||
new uint256[](len - 1);
|
||||
while (c != 0) {
|
||||
if(
|
||||
mapLocks[ids[c]].expirationBlock
|
||||
< block.number ||
|
||||
mapLocks[ids[c]].amount == 0x0) {
|
||||
sortedIDs[p] = ids[c];
|
||||
status[p] = false; c--; ++p;
|
||||
} else {
|
||||
sortedIDs[p] = ids[c];
|
||||
status[p] = true; c--; ++p;
|
||||
}
|
||||
}
|
||||
return(sortedIDs, status);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Adapted from Solady's LibSort.
|
||||
/// (https://github.com/vectorized/solady/blob/main/src/utils/Sort.sol)
|
||||
function sort(uint256[] memory _ids)
|
||||
private
|
||||
view
|
||||
returns(
|
||||
uint256[] memory _sorted,
|
||||
uint256 _len,
|
||||
uint256 _c
|
||||
)
|
||||
{
|
||||
uint256 index;
|
||||
uint256 len = _ids.length;
|
||||
while (index < len)
|
||||
{ if(mapLocks[_ids[index]].sellerKey == 0x0)
|
||||
{ delete _ids[index]; ++index; } else ++index; }
|
||||
|
||||
assembly {
|
||||
let n := mload(_ids)
|
||||
mstore(_ids, 0)
|
||||
for { let i := add(_ids, 32) } 1 {} {
|
||||
i := add(i, 32)
|
||||
if gt(i, add(
|
||||
_ids,
|
||||
mul(n, 32))) { break }
|
||||
let k := mload(i)
|
||||
let j := sub(i, 32)
|
||||
let v := mload(j)
|
||||
if iszero(gt(v, k)) { continue }
|
||||
for {} 1 {} {
|
||||
mstore(add(j, 32), v)
|
||||
j := sub(j, 32)
|
||||
v := mload(j)
|
||||
if iszero(gt(v, k)) { break }}
|
||||
mstore(add(j, 32), k) }
|
||||
mstore(_ids, n)
|
||||
if iszero(lt(mload(_ids), 2)) {
|
||||
let x := add(_ids, 32)
|
||||
let y := add(_ids, 64)
|
||||
let end := add(
|
||||
_ids,
|
||||
mul(add(mload(_ids), 1), 32))
|
||||
for {} 1 {} {
|
||||
if iszero(eq(mload(x), mload(y))) {
|
||||
x := add(x, 32)
|
||||
mstore(x, mload(y)) }
|
||||
y := add(y, 32)
|
||||
if eq(y, end) { break }}
|
||||
mstore(_ids, shr(5, sub(x, _ids))) }
|
||||
_sorted := _ids
|
||||
_len := mload(_ids)
|
||||
switch iszero(mload(add(_ids,32)))
|
||||
case 0 { _c := 0 }
|
||||
case 1 { _c := sub(_len, 1) }
|
||||
}
|
||||
}
|
||||
|
||||
/// @notice Public method that handles `address`
|
||||
/// to `uint256` safe type casting.
|
||||
/// @dev Function sighash: 0x4b2ae980.
|
||||
|
@ -263,12 +263,6 @@ const _abi = [
|
||||
name: "amount",
|
||||
type: "uint256",
|
||||
},
|
||||
{
|
||||
indexed: false,
|
||||
internalType: "uint256",
|
||||
name: "amount",
|
||||
type: "uint256",
|
||||
},
|
||||
],
|
||||
name: "LockReleased",
|
||||
type: "event",
|
||||
|
File diff suppressed because one or more lines are too long
@ -37,6 +37,7 @@ export interface P2PIXInterface extends utils.Interface {
|
||||
"deposit(address,uint96,uint160,bool,bytes32)": FunctionFragment;
|
||||
"getBalance(address,address)": FunctionFragment;
|
||||
"getBalances(address[],address)": FunctionFragment;
|
||||
"getLocksStatus(uint256[])": FunctionFragment;
|
||||
"getPixTarget(address,address)": FunctionFragment;
|
||||
"getValid(address,address)": FunctionFragment;
|
||||
"lock(address,address,address,address,uint256,uint256,bytes32[],uint256[])": FunctionFragment;
|
||||
@ -72,6 +73,7 @@ export interface P2PIXInterface extends utils.Interface {
|
||||
| "deposit"
|
||||
| "getBalance"
|
||||
| "getBalances"
|
||||
| "getLocksStatus"
|
||||
| "getPixTarget"
|
||||
| "getValid"
|
||||
| "lock"
|
||||
@ -132,6 +134,10 @@ export interface P2PIXInterface extends utils.Interface {
|
||||
functionFragment: "getBalances",
|
||||
values: [PromiseOrValue<string>[], PromiseOrValue<string>]
|
||||
): string;
|
||||
encodeFunctionData(
|
||||
functionFragment: "getLocksStatus",
|
||||
values: [PromiseOrValue<BigNumberish>[]]
|
||||
): string;
|
||||
encodeFunctionData(
|
||||
functionFragment: "getPixTarget",
|
||||
values: [PromiseOrValue<string>, PromiseOrValue<string>]
|
||||
@ -265,6 +271,10 @@ export interface P2PIXInterface extends utils.Interface {
|
||||
functionFragment: "getBalances",
|
||||
data: BytesLike
|
||||
): Result;
|
||||
decodeFunctionResult(
|
||||
functionFragment: "getLocksStatus",
|
||||
data: BytesLike
|
||||
): Result;
|
||||
decodeFunctionResult(
|
||||
functionFragment: "getPixTarget",
|
||||
data: BytesLike
|
||||
@ -577,6 +587,11 @@ export interface P2PIX extends BaseContract {
|
||||
overrides?: CallOverrides
|
||||
): Promise<[BigNumber[]]>;
|
||||
|
||||
getLocksStatus(
|
||||
ids: PromiseOrValue<BigNumberish>[],
|
||||
overrides?: CallOverrides
|
||||
): Promise<[BigNumber[], boolean[]]>;
|
||||
|
||||
getPixTarget(
|
||||
seller: PromiseOrValue<string>,
|
||||
token: PromiseOrValue<string>,
|
||||
@ -767,6 +782,11 @@ export interface P2PIX extends BaseContract {
|
||||
overrides?: CallOverrides
|
||||
): Promise<BigNumber[]>;
|
||||
|
||||
getLocksStatus(
|
||||
ids: PromiseOrValue<BigNumberish>[],
|
||||
overrides?: CallOverrides
|
||||
): Promise<[BigNumber[], boolean[]]>;
|
||||
|
||||
getPixTarget(
|
||||
seller: PromiseOrValue<string>,
|
||||
token: PromiseOrValue<string>,
|
||||
@ -957,6 +977,11 @@ export interface P2PIX extends BaseContract {
|
||||
overrides?: CallOverrides
|
||||
): Promise<BigNumber[]>;
|
||||
|
||||
getLocksStatus(
|
||||
ids: PromiseOrValue<BigNumberish>[],
|
||||
overrides?: CallOverrides
|
||||
): Promise<[BigNumber[], boolean[]]>;
|
||||
|
||||
getPixTarget(
|
||||
seller: PromiseOrValue<string>,
|
||||
token: PromiseOrValue<string>,
|
||||
@ -1257,6 +1282,11 @@ export interface P2PIX extends BaseContract {
|
||||
overrides?: CallOverrides
|
||||
): Promise<BigNumber>;
|
||||
|
||||
getLocksStatus(
|
||||
ids: PromiseOrValue<BigNumberish>[],
|
||||
overrides?: CallOverrides
|
||||
): Promise<BigNumber>;
|
||||
|
||||
getPixTarget(
|
||||
seller: PromiseOrValue<string>,
|
||||
token: PromiseOrValue<string>,
|
||||
@ -1424,6 +1454,11 @@ export interface P2PIX extends BaseContract {
|
||||
overrides?: CallOverrides
|
||||
): Promise<PopulatedTransaction>;
|
||||
|
||||
getLocksStatus(
|
||||
ids: PromiseOrValue<BigNumberish>[],
|
||||
overrides?: CallOverrides
|
||||
): Promise<PopulatedTransaction>;
|
||||
|
||||
getPixTarget(
|
||||
seller: PromiseOrValue<string>,
|
||||
token: PromiseOrValue<string>,
|
||||
|
@ -936,10 +936,45 @@ describe("P2PIX", () => {
|
||||
|
||||
const key = await p2pix.callStatic._castAddrToKey(owner.address);
|
||||
|
||||
const lockStatus1 = await p2pix.callStatic.getLocksStatus([1,7,7,2,3,4,5,5,2,3]);
|
||||
const lockStatus2 = await p2pix.callStatic.getLocksStatus([1,2,3]);
|
||||
const lockStatus3 = await p2pix.callStatic.getLocksStatus([7,7,5,14,666]);
|
||||
const lockStatus4 = await p2pix.callStatic.getLocksStatus([]);
|
||||
|
||||
const ls1: [BigNumber[], boolean[]] = [
|
||||
[
|
||||
ethers.BigNumber.from(3),
|
||||
ethers.constants.Two,
|
||||
ethers.constants.One,
|
||||
], [true, true, true] ];
|
||||
|
||||
const ls2: [BigNumber[], boolean[]] = [
|
||||
[
|
||||
ethers.constants.One,
|
||||
ethers.constants.Two,
|
||||
ethers.BigNumber.from(3),
|
||||
], [true, true, true] ];
|
||||
|
||||
const ls3: [BigNumber[], boolean[]] = [
|
||||
[
|
||||
ethers.constants.Zero,
|
||||
], [false] ];
|
||||
|
||||
const ls4 = [[],[]];
|
||||
|
||||
expect(tx1).to.be.ok;
|
||||
expect(tx2).to.be.ok;
|
||||
expect(tx3).to.be.ok;
|
||||
|
||||
expect(lockStatus1[0].toString()).to.equal(ls1[0].toString());
|
||||
expect(lockStatus1[1].toString()).to.equal(ls1[1].toString());
|
||||
expect(lockStatus2[0].toString()).to.equal(ls2[0].toString());
|
||||
expect(lockStatus2[1].toString()).to.equal(ls2[1].toString());
|
||||
expect(lockStatus3[0].toString()).to.equal(ls3[0].toString());
|
||||
expect(lockStatus3[1].toString()).to.equal(ls3[1].toString());
|
||||
expect(lockStatus4[0].toString()).to.equal(ls4[0].toString());
|
||||
expect(lockStatus4[1].toString()).to.equal(ls4[1].toString());
|
||||
|
||||
expect(key)
|
||||
.to.eq(storage1.sellerKey)
|
||||
.and.to.eq(storage2.sellerKey)
|
||||
|
Loading…
x
Reference in New Issue
Block a user