-
Notifications
You must be signed in to change notification settings - Fork 3
/
CasimirArray.sol
49 lines (44 loc) · 1.45 KB
/
CasimirArray.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-License-Identifier: Apache
pragma solidity 0.8.18;
import "../interfaces/ICasimirCore.sol";
/// @title Library to extend array functionality
library CasimirArray {
error IndexOutOfBounds();
error EmptyArray();
function removeUint32Item(uint32[] storage uint32Array, uint index) internal {
if (uint32Array.length == 0) {
revert EmptyArray();
}
if (index >= uint32Array.length) {
revert IndexOutOfBounds();
}
for (uint i = index; i < uint32Array.length - 1; i++) {
uint32Array[i] = uint32Array[i + 1];
}
uint32Array.pop();
}
function removeBytesItem(bytes[] storage bytesArray, uint index) internal {
if (bytesArray.length == 0) {
revert EmptyArray();
}
if (index >= bytesArray.length) {
revert IndexOutOfBounds();
}
for (uint i = index; i < bytesArray.length - 1; i++) {
bytesArray[i] = bytesArray[i + 1];
}
bytesArray.pop();
}
function removeWithdrawalItem(ICasimirCore.Withdrawal[] storage withdrawals, uint index) internal {
if (withdrawals.length == 0) {
revert EmptyArray();
}
if (index >= withdrawals.length) {
revert IndexOutOfBounds();
}
for (uint i = index; i < withdrawals.length - 1; i++) {
withdrawals[i] = withdrawals[i + 1];
}
withdrawals.pop();
}
}