Skip to content

Commit

Permalink
Add schains
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Oct 23, 2023
1 parent 7d8d980 commit 80a3481
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"extends": "solhint:all",
"rules": {
"comprehensive-interface": "error",
"no-global-import": "error",
"private-vars-leading-underscore": "error",
"state-visibility": "error"
}
}
63 changes: 61 additions & 2 deletions contracts/Paymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,66 @@

pragma solidity ^0.8.18;

// cspell:words structs

contract Paymaster {
uint hello;
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {AccessManagedUpgradeable}
from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";

import {IPaymaster, SchainHash} from "./interfaces/IPaymaster.sol";


type ValidatorId is uint256;

struct Schain {
SchainHash hash;
string name;
}

struct Validator {
ValidatorId id;
}

error SchainNotFound(
SchainHash hash
);

contract Paymaster is AccessManagedUpgradeable, IPaymaster {
using EnumerableSet for EnumerableSet.Bytes32Set;

mapping(SchainHash => Schain) public schains;
EnumerableSet.Bytes32Set private _schainHashes;

function addSchain(string calldata name) external override restricted {
SchainHash schainHash = SchainHash.wrap(keccak256(abi.encodePacked(name)));
Schain memory schain = Schain({
hash: schainHash,
name: name
});
_addSchain(schain);
}

function removeSchain(SchainHash schainHash) external override restricted {
_removeSchain(_getSchain(schainHash));
}

// Private

function _addSchain(Schain memory schain) private {
schains[schain.hash] = schain;
_schainHashes.add(SchainHash.unwrap(schain.hash));
}

function _removeSchain(Schain memory schain) private {
delete schains[schain.hash];
_schainHashes.remove(SchainHash.unwrap(schain.hash));
}

function _getSchain(SchainHash hash) private view returns (Schain storage schain) {
if (_schainHashes.contains(SchainHash.unwrap(hash))) {
return schains[hash];
} else {
revert SchainNotFound(hash);
}
}
}
30 changes: 30 additions & 0 deletions contracts/interfaces/IPaymaster.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: AGPL-3.0-only

/*
IPaymaster.sol - Paymaster
Copyright (C) 2023-Present SKALE Labs
@author Dmytro Stebaiev
Paymaster is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Paymaster is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Paymaster. If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity ^0.8.18;


type SchainHash is bytes32;

interface IPaymaster {
function addSchain(string calldata name) external;
function removeSchain(SchainHash schainHash) external;
}
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "@nomicfoundation/hardhat-toolbox";
import {HardhatUserConfig} from "hardhat/config";

const config: HardhatUserConfig = {
"solidity": "0.8.18"
"solidity": "0.8.21"
};

export default config;
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packageManager": "yarn@3.6.4",
"scripts": {
"cleanCompile": "yarn exec hardhat clean && yarn compile",
"compile": "yarn exec hardhat compile && yarn hooks",
"compile": "yarn exec hardhat compile",
"cspell": "yarn exec cspell \"**/*\"",
"eslint": "yarn exec eslint .",
"fullCheck": "yarn compile && yarn lint && yarn tsc && yarn eslint && yarn slither",
Expand Down Expand Up @@ -38,5 +38,9 @@
"ts-node": ">=8.0.0",
"typechain": "^8.1.0",
"typescript": "^5.2.2"
},
"dependencies": {
"@openzeppelin/contracts": "^5.0.0",
"@openzeppelin/contracts-upgradeable": "^5.0.0"
}
}
18 changes: 18 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,22 @@ __metadata:
languageName: node
linkType: hard

"@openzeppelin/contracts-upgradeable@npm:^5.0.0":
version: 5.0.0
resolution: "@openzeppelin/contracts-upgradeable@npm:5.0.0"
peerDependencies:
"@openzeppelin/contracts": 5.0.0
checksum: 4e8a44db153da299d4798fb5cd10aacc537c7fb0fcde099481b92f291f27597db3854b8cc9d2f3916fdeee686944da272852ffdb47a5dca3c93c226e3d96b5e8
languageName: node
linkType: hard

"@openzeppelin/contracts@npm:^5.0.0":
version: 5.0.0
resolution: "@openzeppelin/contracts@npm:5.0.0"
checksum: b182288466dfa1c66e227dcd9761d3205f6451bec5c3550783cfd2f6224d67b45e3d7cb01d7f26fb07cc236bb9fb10ce84268a77c5a5ceafd900b938643f55cd
languageName: node
linkType: hard

"@pkgjs/parseargs@npm:^0.11.0":
version: 0.11.0
resolution: "@pkgjs/parseargs@npm:0.11.0"
Expand Down Expand Up @@ -6075,6 +6091,8 @@ __metadata:
"@nomicfoundation/hardhat-network-helpers": ^1.0.0
"@nomicfoundation/hardhat-toolbox": ^3.0.0
"@nomicfoundation/hardhat-verify": ^1.0.0
"@openzeppelin/contracts": ^5.0.0
"@openzeppelin/contracts-upgradeable": ^5.0.0
"@typechain/ethers-v6": ^0.4.0
"@typechain/hardhat": ^8.0.0
"@types/chai": ^4.3.9
Expand Down

0 comments on commit 80a3481

Please sign in to comment.