Skip to content

Commit

Permalink
forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rrecuero committed Jan 5, 2024
1 parent d2f8616 commit 78764b6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 27 deletions.
44 changes: 30 additions & 14 deletions src/apps/KintoApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ contract KintoApp is
UUPSUpgradeable,
IKintoApp
{

/* ============ Constants ============ */
bytes32 public constant override UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
bytes32 public constant override DEVELOPER_ADMIN = keccak256("DEVELOPER_ADMIN");
Expand All @@ -37,15 +36,14 @@ contract KintoApp is
uint256 public constant RATE_LIMIT_THRESHOLD = 10;
uint256 public constant GAS_LIMIT_PERIOD = 30 days;
uint256 public constant GAS_LIMIT_THRESHOLD = 1e16; // 0.01 ETH

/* ============ State Variables ============ */

uint256 private _nextTokenId;

mapping (address => IKintoApp.Metadata) public appMetadata;
mapping (address => address) public childToParentContract;
mapping (address => mapping (address => bool)) public appSponsoredContracts; // other contracts to be sponsored

mapping(address => IKintoApp.Metadata) public appMetadata;
mapping(address => address) public childToParentContract;
mapping(address => mapping(address => bool)) public appSponsoredContracts; // other contracts to be sponsored

/* ============ Events ============ */

Expand Down Expand Up @@ -83,7 +81,12 @@ contract KintoApp is
* @param childContracts The addresses of the child contracts
* @param appLimits The limits of the app
*/
function registerApp(string calldata _name, address parentContract, address[] calldata childContracts, uint256[4] calldata appLimits) external override {
function registerApp(
string calldata _name,
address parentContract,
address[] calldata childContracts,
uint256[4] calldata appLimits
) external override {
require(appLimits.length == 4, "Invalid app limits");
_updateMetadata(_name, parentContract, childContracts, appLimits);
_nextTokenId++;
Expand All @@ -96,7 +99,10 @@ contract KintoApp is
* @param _contracts The addresses of the contracts
* @param _flags The flags of the contracts
*/
function setSponsoredContracts(address _app, address[] calldata _contracts, bool[] calldata _flags) external override {
function setSponsoredContracts(address _app, address[] calldata _contracts, bool[] calldata _flags)
external
override
{
require(_contracts.length == _flags.length, "Invalid input");
require(msg.sender == appMetadata[_app].developerWallet, "Only developer can set sponsored contracts");
for (uint256 i = 0; i < _contracts.length; i++) {
Expand All @@ -111,7 +117,12 @@ contract KintoApp is
* @param childContracts The addresses of the child contracts
* @param appLimits The limits of the app
*/
function updateMetadata(string calldata _name, address parentContract, address[] calldata childContracts, uint256[4] calldata appLimits) external override {
function updateMetadata(
string calldata _name,
address parentContract,
address[] calldata childContracts,
uint256[4] calldata appLimits
) external override {
require(appLimits.length == 4, "Invalid app limits");
require(msg.sender == appMetadata[parentContract].developerWallet, "Only developer can update metadata");
_updateMetadata(_name, parentContract, childContracts, appLimits);
Expand All @@ -134,7 +145,8 @@ contract KintoApp is
* @return The metadata of the app
*/
function getAppMetadata(address _contract) external view override returns (IKintoApp.Metadata memory) {
address finalContract = childToParentContract[_contract] != address(0) ? childToParentContract[_contract] : _contract;
address finalContract =
childToParentContract[_contract] != address(0) ? childToParentContract[_contract] : _contract;
return appMetadata[finalContract];
}

Expand All @@ -144,7 +156,8 @@ contract KintoApp is
* @return The limits of the app
*/
function getContractLimits(address _contract) external view override returns (uint256[4] memory) {
address finalContract = childToParentContract[_contract] != address(0) ? childToParentContract[_contract] : _contract;
address finalContract =
childToParentContract[_contract] != address(0) ? childToParentContract[_contract] : _contract;
IKintoApp.Metadata memory metadata = appMetadata[finalContract];
return [
metadata.rateLimitPeriod != 0 ? metadata.rateLimitPeriod : RATE_LIMIT_PERIOD,
Expand Down Expand Up @@ -206,7 +219,12 @@ contract KintoApp is
}

/* =========== App metadata params =========== */
function _updateMetadata(string calldata _name, address parentContract, address[] calldata childContracts, uint256[4] calldata appLimits) internal {
function _updateMetadata(
string calldata _name,
address parentContract,
address[] calldata childContracts,
uint256[4] calldata appLimits
) internal {
IKintoApp.Metadata memory metadata = IKintoApp.Metadata({
name: _name,
developerWallet: msg.sender,
Expand All @@ -222,7 +240,6 @@ contract KintoApp is
}
}


/* ============ Disable token transfers ============ */

/**
Expand Down Expand Up @@ -258,5 +275,4 @@ contract KintoApp is
{
return super.supportsInterface(interfaceId);
}

}
25 changes: 17 additions & 8 deletions src/interfaces/IKintoApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,31 @@ interface IKintoApp {
string name;
address developerWallet; // the address that deploys the wallet
bool dsaEnabled; // whether or not this application can request PII from users
uint rateLimitPeriod;
uint rateLimitNumber; // in txs
uint gasLimitPeriod;
uint gasLimitCost; // in eth
uint256 rateLimitPeriod;
uint256 rateLimitNumber; // in txs
uint256 gasLimitPeriod;
uint256 gasLimitCost; // in eth
}

/* ============ State Change ============ */

function registerApp(string calldata _name, address parentContract, address[] calldata childContracts, uint256[4] calldata appLimits) external;
function registerApp(
string calldata _name,
address parentContract,
address[] calldata childContracts,
uint256[4] calldata appLimits
) external;

function enableDSA(address app) external;

function setSponsoredContracts(address _app, address[] calldata _contracts, bool[] calldata _flags) external;

function updateMetadata(string calldata _name, address parentContract, address[] calldata childContracts, uint256[4] calldata appLimits) external;
function updateMetadata(
string calldata _name,
address parentContract,
address[] calldata childContracts,
uint256[4] calldata appLimits
) external;

/* ============ Basic Viewers ============ */

Expand All @@ -31,7 +41,7 @@ interface IKintoApp {
function symbol() external pure returns (string memory);

function getContractLimits(address _contract) external view returns (uint256[4] memory);

function getAppMetadata(address _contract) external view returns (Metadata memory);

function getContractSponsor(address _contract) external view returns (address);
Expand All @@ -43,5 +53,4 @@ interface IKintoApp {
function DEVELOPER_ADMIN() external view returns (bytes32);

function UPGRADER_ROLE() external view returns (bytes32);

}
9 changes: 5 additions & 4 deletions src/paymasters/SponsorPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ contract SponsorPaymaster is Initializable, BasePaymaster, UUPSUpgradeable, Reen
// Check Kinto Gas limit app
ISponsorPaymaster.RateLimitData memory gasLimit = costLimit[userOp.sender][targetAccount];
if (block.timestamp < gasLimit.lastOperationTime + appLimits[2]) {
require(
(gasLimit.ethCostCount + ethMaxCost) <= appLimits[3], "SP: Kinto Gas App limit exceeded"
);
require((gasLimit.ethCostCount + ethMaxCost) <= appLimits[3], "SP: Kinto Gas App limit exceeded");
} else {
// First time need to be checked
require(ethMaxCost <= appLimits[3], "SP: Kinto Gas App limit exceeded");
Expand Down Expand Up @@ -283,7 +281,10 @@ contract SponsorPaymaster is Initializable, BasePaymaster, UUPSUpgradeable, Reen
lastTargetContract = appRegistry.getContractSponsor(targetContracts[targetContracts.length - 1]);
// Last contract must be a contract app
for (uint256 i = 0; i < targetContracts.length - 1; i++) {
if (!appRegistry.isContractSponsoredByApp(lastTargetContract, targetContracts[i]) && targetContracts[i] != sender) {
if (
!appRegistry.isContractSponsoredByApp(lastTargetContract, targetContracts[i])
&& targetContracts[i] != sender
) {
revert("SP: executeBatch targets must be sponsored by the contract or be the sender wallet");
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/wallet/KintoWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,10 @@ contract KintoWallet is Initializable, BaseAccount, TokenCallbackHandler, IKinto
}

function _checkAppWhitelist(address _contract) internal view {
require(appWhitelist[appRegistry.getContractSponsor(_contract)] || _contract == address(this), "KW: contract not whitelisted");
require(
appWhitelist[appRegistry.getContractSponsor(_contract)] || _contract == address(this),
"KW: contract not whitelisted"
);
}

function _onlySelf() internal view {
Expand Down

0 comments on commit 78764b6

Please sign in to comment.