LibUtils

Git Source

Functions

random

simple rng calculation

complexity needs to be increased in prod

function random(uint256 r1, uint256 r2) internal view returns (uint256 r);

Parameters

NameTypeDescription
r1uint256first source of randomness
r2uint256second source of randomness

Returns

NameTypeDescription
ruint256random value

max

Returns the largest of two numbers.

function max(int32 a, int32 b) internal pure returns (int32);

min

Returns the smallest of two numbers.

function min(int32 a, int32 b) internal pure returns (int32);

clamp

Clamps return value to _upperBound

function clamp(uint256 _value, uint256 _upperBound) internal pure returns (uint256);

Parameters

NameTypeDescription
_valueuint256value to be clamped
_upperBounduint256upper bound

Returns

NameTypeDescription
<none>uint256clamped value

abs

Returns the absolute value

function abs(int32 x) internal pure returns (int32);

absDif

Returns the absolute difference

function absDif(int32 a, int32 b) internal pure returns (uint32);

addressToEntityKey

Conversion from address to bytes32

function addressToEntityKey(address _address) internal pure returns (bytes32 key);

removeFromArray

Removes an element from an array of bytes32 if it exists and returns the new array.

function removeFromArray(bytes32[] memory array, bytes32 element) internal pure returns (bytes32[] memory);

Parameters

NameTypeDescription
arraybytes32[]The original array of bytes32 elements.
elementbytes32The bytes32 element to be removed from the array.

Returns

NameTypeDescription
<none>bytes32[]newArray The new array containing all elements of the original array except for the removed element.

stringEq

Checks equality of two strings

function stringEq(string memory a, string memory b) internal pure returns (bool);

safeSubtract

Subtract without underflow

function safeSubtract(uint256 a, uint256 b) internal pure returns (uint256);

arrayIncludes

Check if an element is included in an array

function arrayIncludes(bytes14[] memory array, bytes14 element) internal pure returns (bool);

Parameters

NameTypeDescription
arraybytes14[]The array to check
elementbytes14The element to check for