Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
add prettier and changes (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
iainnash authored Aug 1, 2023
1 parent 9e847bb commit 64b14fa
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 320 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Lint
on: [pull_request]

jobs:
inspect-storage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
cache: "yarn"

- name: Install project dependencies
run: yarn

- name: Run prettier
run: yarn run prettier:check
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

src/lib
15 changes: 15 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 160,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
}
]
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
"dist/"
],
"scripts": {
"prepack": "mkdir -p dist && cp -r src/ dist/contracts && cp -r addresses/ dist/addresses && cp -r out/ dist/artifacts/"
"prepack": "mkdir -p dist && cp -r src/ dist/contracts && cp -r addresses/ dist/addresses && cp -r out/ dist/artifacts/",
"prettier:check": "prettier --check 'src/**/*.sol' 'test/**/*.sol' 'script/**/*.sol'",
"prettier": "prettier --write 'src/**/*.sol' 'test/**/*.sol' 'script/**/*.sol'"
},
"dependencies": {},
"devDependencies": {
"@types/node": "^20.3.2",
"@wagmi/cli": "^1.3.0"
"@wagmi/cli": "^1.3.0",
"prettier": "^3.0.0",
"prettier-plugin-solidity": "^1.1.3"
}
}
2 changes: 1 addition & 1 deletion script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.17;

import "forge-std/Script.sol";

import { ProtocolRewards } from "../src/ProtocolRewards.sol";
import {ProtocolRewards} from "../src/ProtocolRewards.sol";

contract DeployScript is Script {
uint256 internal deployerPK;
Expand Down
52 changes: 8 additions & 44 deletions src/ProtocolRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import {IProtocolRewards} from "./interfaces/IProtocolRewards.sol";

contract ProtocolRewards is IProtocolRewards, EIP712 {
uint256 internal constant WITHDRAW_GAS_LIMIT = 200_000;
bytes32 public constant WITHDRAW_TYPEHASH =
keccak256(
"Withdraw(address owner,uint256 amount,uint256 nonce,uint256 deadline)"
);
bytes32 public constant WITHDRAW_TYPEHASH = keccak256("Withdraw(address owner,uint256 amount,uint256 nonce,uint256 deadline)");

mapping(address => uint256) public balanceOf;
mapping(address => uint256) public nonces;
Expand All @@ -20,10 +17,7 @@ contract ProtocolRewards is IProtocolRewards, EIP712 {
return address(this).balance;
}

function deposit(
address recipient,
string calldata comment
) external payable {
function deposit(address recipient, string calldata comment) external payable {
if (recipient == address(0)) {
revert ADDRESS_ZERO();
}
Expand All @@ -35,11 +29,7 @@ contract ProtocolRewards is IProtocolRewards, EIP712 {
emit Deposit(msg.sender, recipient, msg.value, comment);
}

function depositBatch(
address[] calldata recipients,
uint256[] calldata amounts,
string calldata comment
) external payable {
function depositBatch(address[] calldata recipients, uint256[] calldata amounts, string calldata comment) external payable {
uint256 numRecipients = recipients.length;

if (numRecipients != amounts.length) {
Expand Down Expand Up @@ -95,14 +85,7 @@ contract ProtocolRewards is IProtocolRewards, EIP712 {
address zora,
uint256 zoraReward
) external payable {
if (
msg.value !=
(creatorReward +
mintReferralReward +
createReferralReward +
firstMinterReward +
zoraReward)
) {
if (msg.value != (creatorReward + mintReferralReward + createReferralReward + firstMinterReward + zoraReward)) {
revert INVALID_DEPOSIT();
}

Expand Down Expand Up @@ -152,39 +135,22 @@ contract ProtocolRewards is IProtocolRewards, EIP712 {

emit Withdraw(owner, amount);

(bool success, ) = owner.call{value: amount, gas: WITHDRAW_GAS_LIMIT}(
""
);
(bool success, ) = owner.call{value: amount, gas: WITHDRAW_GAS_LIMIT}("");

if (!success) {
revert TRANSFER_FAILED();
}
}

function withdrawWithSig(
address owner,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external {
function withdrawWithSig(address owner, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external {
if (block.timestamp > deadline) {
revert SIGNATURE_DEADLINE_EXPIRED();
}

bytes32 withdrawHash;

unchecked {
withdrawHash = keccak256(
abi.encode(
WITHDRAW_TYPEHASH,
owner,
amount,
nonces[owner]++,
deadline
)
);
withdrawHash = keccak256(abi.encode(WITHDRAW_TYPEHASH, owner, amount, nonces[owner]++, deadline));
}

bytes32 digest = _hashTypedDataV4(withdrawHash);
Expand All @@ -205,9 +171,7 @@ contract ProtocolRewards is IProtocolRewards, EIP712 {

emit Withdraw(owner, amount);

(bool success, ) = owner.call{value: amount, gas: WITHDRAW_GAS_LIMIT}(
""
);
(bool success, ) = owner.call{value: amount, gas: WITHDRAW_GAS_LIMIT}("");

if (!success) {
revert TRANSFER_FAILED();
Expand Down
7 changes: 2 additions & 5 deletions src/abstract/ERC1155/ERC1155Rewards.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import { RewardSplits } from "../RewardSplits.sol";
import {RewardSplits} from "../RewardSplits.sol";

contract ERC1155RewardsStorage {
mapping(uint256 => address) public createReferrals;
}

abstract contract ERC1155Rewards is RewardSplits {
constructor(address _protocolRewards, address _zoraRewardRecipient)
payable
RewardSplits(_protocolRewards, _zoraRewardRecipient)
{ }
constructor(address _protocolRewards, address _zoraRewardRecipient) payable RewardSplits(_protocolRewards, _zoraRewardRecipient) {}

function _handleRewardsAndGetValueSent(
uint256 msgValue,
Expand Down
19 changes: 4 additions & 15 deletions src/abstract/ERC721/ERC721Rewards.sol
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import { RewardSplits } from "../RewardSplits.sol";

import {RewardSplits} from "../RewardSplits.sol";

abstract contract ERC721Rewards is RewardSplits {
constructor(address _protocolRewards, address _zoraRewardRecipient)
payable
RewardSplits(_protocolRewards, _zoraRewardRecipient)
{ }

function _handleRewards(
uint256 msgValue,
uint256 numTokens,
uint256 salePrice,
address creator,
address mintReferral,
address createReferral
) internal {
constructor(address _protocolRewards, address _zoraRewardRecipient) payable RewardSplits(_protocolRewards, _zoraRewardRecipient) {}

function _handleRewards(uint256 msgValue, uint256 numTokens, uint256 salePrice, address creator, address mintReferral, address createReferral) internal {
if (creator == address(0)) {
revert CREATOR_FUNDS_RECIPIENT_NOT_SET();
}
Expand Down
52 changes: 12 additions & 40 deletions src/abstract/RewardSplits.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import { IProtocolRewards } from "../interfaces/IProtocolRewards.sol";
import {IProtocolRewards} from "../interfaces/IProtocolRewards.sol";

abstract contract RewardSplits {
error CREATOR_FUNDS_RECIPIENT_NOT_SET();
Expand Down Expand Up @@ -38,47 +38,26 @@ abstract contract RewardSplits {
return numTokens * TOTAL_REWARD_PER_MINT;
}

function computeFreeMintRewards(uint256 numTokens)
public
pure
returns (
uint256 creatorReward,
uint256 mintReferralReward,
uint256 createReferralReward,
uint256 firstMinterReward,
uint256 zoraReward
)
{
function computeFreeMintRewards(
uint256 numTokens
) public pure returns (uint256 creatorReward, uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) {
creatorReward = numTokens * CREATOR_REWARD;
mintReferralReward = numTokens * MINT_REFERRAL_FREE_MINT_REWARD;
createReferralReward = numTokens * CREATE_REFERRAL_FREE_MINT_REWARD;
firstMinterReward = numTokens * FIRST_MINTER_REWARD;
zoraReward = numTokens * ZORA_FREE_MINT_REWARD;
}

function computePaidMintRewards(uint256 numTokens)
public
pure
returns (
uint256 mintReferralReward,
uint256 createReferralReward,
uint256 firstMinterReward,
uint256 zoraReward
)
{
function computePaidMintRewards(
uint256 numTokens
) public pure returns (uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) {
mintReferralReward = numTokens * MINT_REFERRAL_PAID_MINT_REWARD;
createReferralReward = numTokens * CREATE_REFERRAL_PAID_MINT_REWARD;
firstMinterReward = numTokens * FIRST_MINTER_REWARD;
zoraReward = numTokens * ZORA_PAID_MINT_REWARD;
}

function _depositFreeMintRewards(
uint256 totalReward,
uint256 numTokens,
address creator,
address mintReferral,
address createReferral
) internal {
function _depositFreeMintRewards(uint256 totalReward, uint256 numTokens, address creator, address mintReferral, address createReferral) internal {
(
uint256 creatorReward,
uint256 mintReferralReward,
Expand All @@ -95,7 +74,7 @@ abstract contract RewardSplits {
createReferral = zoraRewardRecipient;
}

protocolRewards.depositRewards{ value: totalReward }(
protocolRewards.depositRewards{value: totalReward}(
creator,
creatorReward,
mintReferral,
Expand All @@ -109,15 +88,8 @@ abstract contract RewardSplits {
);
}

function _depositPaidMintRewards(
uint256 totalReward,
uint256 numTokens,
address creator,
address mintReferral,
address createReferral
) internal {
(uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) =
computePaidMintRewards(numTokens);
function _depositPaidMintRewards(uint256 totalReward, uint256 numTokens, address creator, address mintReferral, address createReferral) internal {
(uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) = computePaidMintRewards(numTokens);

if (mintReferral == address(0)) {
mintReferral = zoraRewardRecipient;
Expand All @@ -127,7 +99,7 @@ abstract contract RewardSplits {
createReferral = zoraRewardRecipient;
}

protocolRewards.depositRewards{ value: totalReward }(
protocolRewards.depositRewards{value: totalReward}(
address(0),
0,
mintReferral,
Expand Down
8 changes: 5 additions & 3 deletions src/interfaces/IProtocolRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ interface IProtocolRewards {
address zora,
uint256 zoraReward
) external payable;

function deposit(address recipient, string calldata comment) external payable;
function depositBatch(address[] calldata recipients, uint256[] calldata amounts, string calldata comment)
external
payable;

function depositBatch(address[] calldata recipients, uint256[] calldata amounts, string calldata comment) external payable;

function withdraw(uint256 amount) external;

function withdrawWithSig(address owner, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external;
}
Loading

0 comments on commit 64b14fa

Please sign in to comment.