Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
style: format code (paritytech#732)
Browse files Browse the repository at this point in the history
* chore: format code

* format code

* add format hook

* add lint when commit
  • Loading branch information
yrong authored Dec 12, 2022
1 parent bbf2b2f commit 23510f0
Show file tree
Hide file tree
Showing 39 changed files with 287 additions and 321 deletions.
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

cd core && pnpm lint && pnpm format

9 changes: 7 additions & 2 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",
"postinstall": "cd .. && husky install",
"build": "turbo run build",
"test": "turbo run test",
"lint": "turbo run lint"
"lint": "turbo run lint",
"format": "turbo run format",
"size": "turbo run size",
"coverage": "turbo run coverage"
},
"devDependencies": {
"turbo": "^1.6.3"
"turbo": "^1.6.3",
"husky": "^8.0.1"
},
"overrides": {
"@[email protected]>@polkadot/util": "10.1.11",
Expand Down
47 changes: 28 additions & 19 deletions core/packages/contracts/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"prefer-const": ["off", {
"destructuring": "any",
"ignoreReadBeforeAssign": false
}]
},
"ignorePatterns": ["dist", "artifacts", "build", "contracts", "src/**/*.ts", "truffle-config.js"]
}
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"prefer-const": [
"off",
{
"destructuring": "any",
"ignoreReadBeforeAssign": false
}
]
},
"ignorePatterns": [
"dist",
"artifacts",
"build",
"contracts",
"src/**/*.ts",
"truffle-config.js",
"coverage"
]
}
3 changes: 2 additions & 1 deletion core/packages/contracts/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"tabWidth": 4,
"singleQuote": false,
"bracketSpacing": true,
"explicitTypes": "always"
"explicitTypes": "always",
"plugins": ["prettier-plugin-solidity"]
}
},
{
Expand Down
6 changes: 5 additions & 1 deletion core/packages/contracts/contracts/BasicInboundChannel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ contract BasicInboundChannel {
bytes calldata proof
) external {
bytes32 leafHash = keccak256(abi.encode(bundle));
bytes32 commitment = MerkleProof.computeRootFromProofAndSide(leafHash, leafProof, hashSides);
bytes32 commitment = MerkleProof.computeRootFromProofAndSide(
leafHash,
leafProof,
hashSides
);

require(parachainClient.verifyCommitment(commitment, proof), "Invalid proof");
require(bundle.sourceChannelID == sourceChannelID, "Invalid source channel");
Expand Down
11 changes: 2 additions & 9 deletions core/packages/contracts/contracts/BasicOutboundChannel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@ import "./OutboundChannel.sol";

// BasicOutboundChannel is a basic channel that just sends messages with a nonce.
contract BasicOutboundChannel is OutboundChannel, ChannelAccess, AccessControl {

// Governance contracts will administer using this role.
bytes32 public constant CONFIG_UPDATE_ROLE = keccak256("CONFIG_UPDATE_ROLE");

mapping(address => uint64) public nonce;

event Message(
address source,
address account,
uint64 nonce,
bytes payload
);
event Message(address source, address account, uint64 nonce, bytes payload);

constructor() {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
Expand All @@ -28,8 +22,7 @@ contract BasicOutboundChannel is OutboundChannel, ChannelAccess, AccessControl {
function initialize(
address _configUpdater,
address[] memory defaultOperators
)
external onlyRole(DEFAULT_ADMIN_ROLE) {
) external onlyRole(DEFAULT_ADMIN_ROLE) {
// Set initial configuration
grantRole(CONFIG_UPDATE_ROLE, _configUpdater);
for (uint i = 0; i < defaultOperators.length; i++) {
Expand Down
37 changes: 20 additions & 17 deletions core/packages/contracts/contracts/BeefyClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import "./utils/MerkleProof.sol";
* @title BeefyClient
*/
contract BeefyClient is Ownable {

/* Events */

/**
Expand Down Expand Up @@ -152,13 +151,11 @@ contract BeefyClient is Ownable {
error PrevRandaoAlreadyCaptured();
error PrevRandaoNotCaptured();


constructor(uint256 _randaoCommitDelay, uint256 _randaoCommitExpiration) {
randaoCommitDelay = _randaoCommitDelay;
randaoCommitExpiration = _randaoCommitExpiration;
}


// Once-off post-construction call to set initial configuration.
function initialize(
uint64 _initialBeefyBlock,
Expand Down Expand Up @@ -345,7 +342,8 @@ contract BeefyClient is Ownable {
bool leafIsValid = MMRProof.verifyLeafProof(
commitment.payload.mmrRootHash,
keccak256(encodeMMRLeaf(leaf)),
leafProof, leafProofOrder
leafProof,
leafProofOrder
);
if (!leafIsValid) {
revert InvalidMMRLeafProof();
Expand All @@ -367,17 +365,20 @@ contract BeefyClient is Ownable {
* @param leafHash contains the merkle leaf to be verified
* @param proof contains simplified mmr proof
*/
function verifyMMRLeafProof(bytes32 leafHash, bytes32[] calldata proof, uint256 proofOrder)
external
view
returns (bool)
{
function verifyMMRLeafProof(
bytes32 leafHash,
bytes32[] calldata proof,
uint256 proofOrder
) external view returns (bool) {
return MMRProof.verifyLeafProof(latestMMRRoot, leafHash, proof, proofOrder);
}

/* Private Functions */

function createTaskID(address account, bytes32 commitmentHash) internal pure returns (bytes32 value) {
function createTaskID(
address account,
bytes32 commitmentHash
) internal pure returns (bytes32 value) {
assembly {
mstore(0x00, account)
mstore(0x20, commitmentHash)
Expand Down Expand Up @@ -453,7 +454,7 @@ contract BeefyClient is Ownable {
revert InvalidValidatorProof();
}

for (uint256 i = 0; i < signatureCount;) {
for (uint256 i = 0; i < signatureCount; ) {
ValidatorProof calldata proof = proofs[i];

(uint256 x, uint8 y) = Bitfield.toLocation(proof.index);
Expand Down Expand Up @@ -530,18 +531,20 @@ contract BeefyClient is Ownable {
/**
* @dev Helper to create an initial validator bitfield.
*/
function createInitialBitfield(uint256[] calldata bitsToSet, uint256 length)
external
pure
returns (uint256[] memory)
{
function createInitialBitfield(
uint256[] calldata bitsToSet,
uint256 length
) external pure returns (uint256[] memory) {
return Bitfield.createBitfield(bitsToSet, length);
}

/**
* @dev Helper to create a final bitfield, with random validator selections.
*/
function createFinalBitfield(bytes32 commitmentHash, uint256[] calldata bitfield) external view returns (uint256[] memory) {
function createFinalBitfield(
bytes32 commitmentHash,
uint256[] calldata bitfield
) external view returns (uint256[] memory) {
Task storage task = tasks[createTaskID(msg.sender, commitmentHash)];
return
Bitfield.randomNBitsWithPriorCheck(
Expand Down
12 changes: 3 additions & 9 deletions core/packages/contracts/contracts/ChannelAccess.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@ pragma solidity ^0.8.9;
* - Default Operator: an account that can submit messages for all users
*
* Much of this logic was inspired from the ERC777 operators feature.
*/
*/
abstract contract ChannelAccess {
mapping(address => bool) private defaultOperators;
mapping(address => mapping(address => bool)) private operators;

event OperatorAuthorized(
address operator,
address user
);
event OperatorAuthorized(address operator, address user);

event OperatorRevoked(
address operator,
address user
);
event OperatorRevoked(address operator, address user);

// Authorize a default operator
function _authorizeDefaultOperator(address operator) internal {
Expand Down
1 change: 0 additions & 1 deletion core/packages/contracts/contracts/ChannelRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "./OutboundChannel.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract ChannelRegistry is Ownable {

struct Channel {
address inbound;
address outbound;
Expand Down
27 changes: 7 additions & 20 deletions core/packages/contracts/contracts/DOTApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,13 @@ contract DOTApp is FeeController, AccessControl {
error UnknownChannel(uint32 id);
error Unauthorized();

constructor(
WrappedToken _token,
address feeBurner,
ChannelRegistry channelRegistry
) {
constructor(WrappedToken _token, address feeBurner, ChannelRegistry channelRegistry) {
token = _token;
registry = channelRegistry;
_setupRole(FEE_BURNER_ROLE, feeBurner);
}

function burn(
bytes32 _recipient,
uint256 _amount,
uint32 _channelID
) external {
function burn(bytes32 _recipient, uint256 _amount, uint32 _channelID) external {
token.burn(msg.sender, _amount);

address channel = registry.outboundChannelForID(_channelID);
Expand All @@ -48,11 +40,7 @@ contract DOTApp is FeeController, AccessControl {
emit Burned(msg.sender, _recipient, _amount);
}

function mint(
bytes32 _sender,
address _recipient,
uint256 _amount
) external {
function mint(bytes32 _sender, address _recipient, uint256 _amount) external {
if (!registry.isInboundChannel(msg.sender)) {
revert Unauthorized();
}
Expand All @@ -61,11 +49,10 @@ contract DOTApp is FeeController, AccessControl {
}

// Incentivized channel calls this to charge (burn) fees
function handleFee(address feePayer, uint256 _amount)
external
override
onlyRole(FEE_BURNER_ROLE)
{
function handleFee(
address feePayer,
uint256 _amount
) external override onlyRole(FEE_BURNER_ROLE) {
token.burn(feePayer, _amount);
}
}
28 changes: 11 additions & 17 deletions core/packages/contracts/contracts/ERC20App.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,9 @@ contract ERC20App is AccessControl {
uint128 fee
);

event Unlocked(
address token,
bytes32 sender,
address recipient,
uint128 amount
);
event Unlocked(address token, bytes32 sender, address recipient, uint128 amount);

constructor(
ERC20Vault erc20vault,
ChannelRegistry channelRegistry
) {
constructor(ERC20Vault erc20vault, ChannelRegistry channelRegistry) {
vault = erc20vault;
registry = channelRegistry;
}
Expand Down Expand Up @@ -75,19 +67,21 @@ contract ERC20App is AccessControl {
if (_paraID == 0) {
(call, weight) = ERC20AppPallet.mint(_token, msg.sender, _recipient, _amount);
} else {
(call, weight) = ERC20AppPallet.mintAndForward(_token, msg.sender, _recipient, _amount, _paraID, _fee);
(call, weight) = ERC20AppPallet.mintAndForward(
_token,
msg.sender,
_recipient,
_amount,
_paraID,
_fee
);
}
OutboundChannel(channel).submit(msg.sender, call, weight);

emit Locked(_token, msg.sender, _recipient, _amount, _paraID, _fee);
}

function unlock(
address _token,
bytes32 _sender,
address _recipient,
uint128 _amount
) external {
function unlock(address _token, bytes32 _sender, address _recipient, uint128 _amount) external {
if (!registry.isInboundChannel(msg.sender)) {
revert Unauthorized();
}
Expand Down
10 changes: 2 additions & 8 deletions core/packages/contracts/contracts/ERC20Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ contract ERC20Vault is Ownable {
/// @param _sender The address of the sender.
/// @param _token The address of the Token.
/// @param _amount The amount being deposited.
function deposit(address _sender, address _token, uint128 _amount)
external
onlyOwner
{
function deposit(address _sender, address _token, uint128 _amount) external onlyOwner {
balances[_token] = balances[_token] + _amount;
// TODO: Transfer ERC20 tokens safely. https://linear.app/snowfork/issue/SNO-366
if (!IERC20(_token).transferFrom(_sender, address(this), _amount)) {
Expand All @@ -53,10 +50,7 @@ contract ERC20Vault is Ownable {
/// @param _recipient The address that will receive funds.
/// @param _token The address of the Token.
/// @param _amount The amount being deposited.
function withdraw(address _recipient, address _token, uint128 _amount)
external
onlyOwner
{
function withdraw(address _recipient, address _token, uint128 _amount) external onlyOwner {
if (_amount > balances[_token]) {
revert InsufficientBalance();
}
Expand Down
Loading

0 comments on commit 23510f0

Please sign in to comment.