Skip to content

Commit

Permalink
Merge branch 'main' into deploy-factory-create2
Browse files Browse the repository at this point in the history
  • Loading branch information
cpb8010 authored Dec 19, 2024
2 parents 524c88d + 8a14c35 commit 896e0f8
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 115 deletions.
2 changes: 1 addition & 1 deletion src/SsoAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ contract SsoAccount is Initializable, HookManager, ERC1271Handler, TokenCallback
// If there is not enough balance for the transaction, the account should reject it
// on the validation step to prevent paying fees for revertable transactions.
if (_transaction.totalRequiredBalance() > address(this).balance) {
revert Errors.INSUFFICIENT_FUNDS();
revert Errors.INSUFFICIENT_FUNDS(_transaction.totalRequiredBalance(), address(this).balance);
}

// While the suggested signed hash is usually provided, it is generally
Expand Down
2 changes: 1 addition & 1 deletion src/auth/BootloaderAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Errors } from "../libraries/Errors.sol";
abstract contract BootloaderAuth {
modifier onlyBootloader() {
if (msg.sender != BOOTLOADER_FORMAL_ADDRESS) {
revert Errors.NOT_FROM_BOOTLOADER();
revert Errors.NOT_FROM_BOOTLOADER(msg.sender);
}
_;
}
Expand Down
2 changes: 1 addition & 1 deletion src/auth/HookAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract contract HookAuth {

modifier onlyHook() {
if (!_isHook(msg.sender)) {
revert Errors.NOT_FROM_HOOK();
revert Errors.NOT_FROM_HOOK(msg.sender);
}
_;
}
Expand Down
2 changes: 1 addition & 1 deletion src/auth/SelfAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Errors } from "../libraries/Errors.sol";
abstract contract SelfAuth {
modifier onlySelf() {
if (msg.sender != address(this)) {
revert Errors.NOT_FROM_SELF();
revert Errors.NOT_FROM_SELF(msg.sender);
}
_;
}
Expand Down
4 changes: 2 additions & 2 deletions src/batch/BatchCaller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ abstract contract BatchCaller is SelfAuth {
}

if (!_calls[i].allowFailure && !success) {
revert Errors.CALL_FAILED();
revert Errors.CALL_FAILED(i);
}
}

if (totalValue != msg.value) {
revert Errors.MsgValueMismatch(msg.value, totalValue);
revert Errors.MSG_VALUE_MISMATCH(msg.value, totalValue);
}
}
}
2 changes: 1 addition & 1 deletion src/helpers/Logger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ library Logger {
}
}

function logUint(uint intToLog) internal view {
function logUint(uint256 intToLog) internal view {
if (block.chainid == 260) {
console.logUint(intToLog);
}
Expand Down
51 changes: 18 additions & 33 deletions src/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,51 @@ library Errors {
ACCOUNT
//////////////////////////////////////////////////////////////*/

error INSUFFICIENT_FUNDS();
error INSUFFICIENT_FUNDS(uint256 required, uint256 available);
error FEE_PAYMENT_FAILED();
error METHOD_NOT_IMPLEMENTED();

/*//////////////////////////////////////////////////////////////
LINKED LIST
//////////////////////////////////////////////////////////////*/

error INVALID_PREV();
error INVALID_PREV_BYTES(bytes prevValue, bytes oldValue);
error INVALID_PREV_ADDR(address prevValue, address oldValue);
// Bytes
error INVALID_BYTES();
error BYTES_ALREADY_EXISTS();
error BYTES_NOT_EXISTS();
error INVALID_BYTES(uint256 length);
error BYTES_ALREADY_EXISTS(bytes length);
error BYTES_NOT_EXISTS(bytes lookup);
// Address
error INVALID_ADDRESS();
error ADDRESS_ALREADY_EXISTS();
error ADDRESS_NOT_EXISTS();

/*//////////////////////////////////////////////////////////////
OWNER MANAGER
//////////////////////////////////////////////////////////////*/

error INVALID_PUBKEY_LENGTH();
error INVALID_ADDRESS(address valid);
error ADDRESS_ALREADY_EXISTS(address exists);
error ADDRESS_NOT_EXISTS(address notExists);

/*//////////////////////////////////////////////////////////////
VALIDATOR MANAGER
//////////////////////////////////////////////////////////////*/

error VALIDATOR_ERC165_FAIL();
error VALIDATOR_ERC165_FAIL(address validator);

/*//////////////////////////////////////////////////////////////
HOOK MANAGER
//////////////////////////////////////////////////////////////*/

error EMPTY_HOOK_ADDRESS();
error HOOK_ERC165_FAIL();
error INVALID_KEY();

/*//////////////////////////////////////////////////////////////
MODULE MANAGER
//////////////////////////////////////////////////////////////*/

error EMPTY_MODULE_ADDRESS();
error RECURSIVE_MODULE_CALL();
error MODULE_ERC165_FAIL();
error EMPTY_HOOK_ADDRESS(uint256 hookAndDataLength);
error HOOK_ERC165_FAIL(address hookAddress, bool isValidation);
error INVALID_KEY(bytes32 key);

/*//////////////////////////////////////////////////////////////
AUTH
//////////////////////////////////////////////////////////////*/

error NOT_FROM_BOOTLOADER();
error NOT_FROM_MODULE();
error NOT_FROM_HOOK();
error NOT_FROM_SELF();
error NOT_FROM_SELF_OR_MODULE();
error NOT_FROM_BOOTLOADER(address notBootloader);
error NOT_FROM_HOOK(address notHook);
error NOT_FROM_SELF(address notSelf);

/*//////////////////////////////////////////////////////////////
BatchCaller
//////////////////////////////////////////////////////////////*/

error CALL_FAILED();
error MsgValueMismatch(uint256 actualValue, uint256 expectedValue);
error CALL_FAILED(uint256 batchCallIndex);
error MSG_VALUE_MISMATCH(uint256 actualValue, uint256 expectedValue);
}
65 changes: 24 additions & 41 deletions src/libraries/JsmnSolLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ library JsmnSolLib {
PRIMITIVE
}

uint constant RETURN_SUCCESS = 0;
uint constant RETURN_ERROR_INVALID_JSON = 1;
uint constant RETURN_ERROR_PART = 2;
uint constant RETURN_ERROR_NO_MEM = 3;
uint256 constant RETURN_SUCCESS = 0;
uint256 constant RETURN_ERROR_INVALID_JSON = 1;
uint256 constant RETURN_ERROR_PART = 2;
uint256 constant RETURN_ERROR_NO_MEM = 3;

struct Token {
JsmnType jsmnType;
uint start;
uint256 start;
bool startSet;
uint end;
uint256 end;
bool endSet;
uint8 size;
}

struct Parser {
uint pos;
uint toknext;
int toksuper;
uint256 pos;
uint256 toknext;
int256 toksuper;
}

function init(uint length) internal pure returns (Parser memory, Token[] memory) {
function init(uint256 length) internal pure returns (Parser memory, Token[] memory) {
Parser memory p = Parser(0, 0, -1);
Token[] memory t = new Token[](length);
return (p, t);
Expand All @@ -68,7 +68,7 @@ library JsmnSolLib {
return (true, token);
}

function fillToken(Token memory token, JsmnType jsmnType, uint start, uint end) internal pure {
function fillToken(Token memory token, JsmnType jsmnType, uint256 start, uint256 end) internal pure {
token.jsmnType = jsmnType;
token.start = start;
token.startSet = true;
Expand All @@ -78,7 +78,7 @@ library JsmnSolLib {
}

function parseString(Parser memory parser, Token[] memory tokens, bytes memory s) internal pure returns (uint) {
uint start = parser.pos;
uint256 start = parser.pos;
bool success;
Token memory token;
parser.pos++;
Expand Down Expand Up @@ -124,7 +124,7 @@ library JsmnSolLib {
function parsePrimitive(Parser memory parser, Token[] memory tokens, bytes memory s) internal pure returns (uint) {
bool found = false;
uint start = parser.pos;
uint256 start = parser.pos;
bool success;
bytes1 c;
Token memory token;
Expand Down Expand Up @@ -155,16 +155,16 @@ library JsmnSolLib {
return RETURN_SUCCESS;
}
function parse(string memory json, uint numberElements) internal pure returns (uint, Token[] memory tokens, uint) {
function parse(string memory json, uint256 numberElements) internal pure returns (uint, Token[] memory tokens, uint) {
bytes memory s = bytes(json);
bool success;
Parser memory parser;
(parser, tokens) = init(numberElements);
// Token memory token;
uint r;
uint count = parser.toknext;
uint i;
uint256 r;
uint256 count = parser.toknext;
uint256 i;
Token memory token;
for (; parser.pos < s.length; parser.pos++) {
Expand Down Expand Up @@ -296,10 +296,10 @@ library JsmnSolLib {
return (RETURN_SUCCESS, tokens, parser.toknext);
}
function getBytes(string memory json, uint start, uint end) internal pure returns (string memory) {
function getBytes(string memory json, uint256 start, uint256 end) internal pure returns (string memory) {
bytes memory s = bytes(json);
bytes memory result = new bytes(end - start);
for (uint i = start; i < end; i++) {
for (uint256 i = start; i < end; i++) {
result[i - start] = s[i];
}
return string(result);
Expand All @@ -311,12 +311,12 @@ library JsmnSolLib {
}
// parseInt(parseFloat*10^_b)
function parseInt(string memory _a, uint _b) internal pure returns (int) {
function parseInt(string memory _a, uint256 _b) internal pure returns (int) {
bytes memory bresult = bytes(_a);
int mint = 0;
int256 mint = 0;
bool decimals = false;
bool negative = false;
for (uint i = 0; i < bresult.length; i++) {
for (uint256 i = 0; i < bresult.length; i++) {
if ((i == 0) && (bresult[i] == "-")) {
negative = true;
}
Expand All @@ -334,23 +334,6 @@ library JsmnSolLib {
return mint;
}
function uint2str(uint i) internal pure returns (string memory) {
if (i == 0) return "0";
uint j = i;
uint len;
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint k = len - 1;
while (i != 0) {
bstr[k--] = bytes1(uint8(48 + (i % 10)));
i /= 10;
}
return string(bstr);
}
function parseBool(string memory _a) internal pure returns (bool) {
if (strCompare(_a, "true") == 0) {
return true;
Expand All @@ -362,9 +345,9 @@ library JsmnSolLib {
function strCompare(string memory _a, string memory _b) internal pure returns (int) {
bytes memory a = bytes(_a);
bytes memory b = bytes(_b);
uint minLength = a.length;
uint256 minLength = a.length;
if (b.length < minLength) minLength = b.length;
for (uint i = 0; i < minLength; i++)
for (uint256 i = 0; i < minLength; i++)
if (a[i] < b[i]) return -1;
else if (a[i] > b[i]) return 1;
if (a.length < b.length) return -1;
Expand Down
Loading

0 comments on commit 896e0f8

Please sign in to comment.