Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revenue share #12

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions contracts/GuildPin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ contract GuildPin is IGuildPin, Initializable, OwnableUpgradeable, UUPSUpgradeab
// }

function claim(
address payToken,
PinDataParams memory pinData,
address payable adminTreasury,
uint256 adminFee,
uint256 signedAt,
string calldata cid,
bytes calldata signature
Expand All @@ -83,10 +84,7 @@ contract GuildPin is IGuildPin, Initializable, OwnableUpgradeable, UUPSUpgradeab
claimedTokens[pinData.receiver][pinData.guildAction][pinData.guildId] != 0 ||
claimerUserIds[pinData.userId][pinData.guildAction][pinData.guildId]
) revert AlreadyClaimed();
if (!isValidSignature(pinData, signedAt, cid, signature)) revert IncorrectSignature();

uint256 fee = fee[payToken];
if (fee == 0) revert IncorrectPayToken(payToken);
if (!isValidSignature(pinData, adminTreasury, adminFee, signedAt, cid, signature)) revert IncorrectSignature();

uint256 tokenId = totalSupply() + 1;

Expand All @@ -109,11 +107,11 @@ contract GuildPin is IGuildPin, Initializable, OwnableUpgradeable, UUPSUpgradeab
claimerUserIds[pinData.userId][pinData.guildAction][pinData.guildId] = true;

// Fee collection
// When there is no msg.value, try transferring ERC20
// When there is msg.value, ensure it's the correct amount
if (msg.value == 0) treasury.sendTokenFrom(msg.sender, payToken, fee);
else if (msg.value != fee) revert IncorrectFee(msg.value, fee);
else treasury.sendEther(fee);
uint256 guildFee = fee;
if (msg.value == guildFee + adminFee) {
treasury.sendEther(guildFee);
if (adminTreasury != address(0)) adminTreasury.sendEther(adminFee);
} else revert IncorrectFee(msg.value, guildFee + adminFee);

_safeMint(pinData.receiver, tokenId);

Expand Down Expand Up @@ -145,7 +143,8 @@ contract GuildPin is IGuildPin, Initializable, OwnableUpgradeable, UUPSUpgradeab
bytes calldata signature
) external {
if (signedAt < block.timestamp - SIGNATURE_VALIDITY) revert ExpiredSignature();
if (!isValidSignature(pinData, signedAt, newCid, signature)) revert IncorrectSignature();
if (!isValidSignature(pinData, payable(address(0)), 0, signedAt, newCid, signature))
revert IncorrectSignature();

uint256 tokenId = claimedTokens[pinData.receiver][pinData.guildAction][pinData.guildId];
if (tokenId == 0) revert NonExistentToken(tokenId);
Expand Down Expand Up @@ -222,6 +221,8 @@ contract GuildPin is IGuildPin, Initializable, OwnableUpgradeable, UUPSUpgradeab
/// @notice Checks the validity of the signature for the given params.
function isValidSignature(
PinDataParams memory pinData,
address payable adminTreasury,
uint256 adminFee,
uint256 signedAt,
string calldata cid,
bytes calldata signature
Expand All @@ -235,6 +236,8 @@ contract GuildPin is IGuildPin, Initializable, OwnableUpgradeable, UUPSUpgradeab
pinData.guildId,
pinData.guildName,
pinData.createdAt,
adminTreasury,
adminFee,
signedAt,
cid,
block.chainid,
Expand Down
11 changes: 4 additions & 7 deletions contracts/interfaces/IGuildPin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ interface IGuildPin {

/// @notice Claims tokens to the given address.
/// @dev The contract needs to be approved if ERC20 tokens are used.
/// @param payToken The address of the token that's used for paying the minting fees. 0 for ether.
/// @param pinData The Guild-related data, see {PinDataParams}.
/// @param adminTreasury The address where the pinned guild collects fees paid to them.
/// @param adminFee The fee to pay to the guild where the Pin is minted.
/// @param signedAt The timestamp marking the time when the data were signed.
/// @param cid The cid used to construct the tokenURI for the token to be minted.
/// @param signature The following signed by validSigner: pinData, signedAt, cid, chainId, the contract's address.
function claim(
address payToken,
PinDataParams memory pinData,
address payable adminTreasury,
uint256 adminFee,
uint256 signedAt,
string calldata cid,
bytes calldata signature
Expand Down Expand Up @@ -139,11 +141,6 @@ interface IGuildPin {
/// @param requiredAmount The amount of fees required for minting.
error IncorrectFee(uint256 paid, uint256 requiredAmount);

/// @notice Error thrown when such a token is attempted to be used for paying that has no fee set.
/// @dev The owner should set a fee for the token to solve this issue.
/// @param token The address of the token that cannot be used.
error IncorrectPayToken(address token);

/// @notice Error thrown when the sender is not permitted to do a specific action.
error IncorrectSender();

Expand Down
13 changes: 5 additions & 8 deletions contracts/interfaces/ITreasuryManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,26 @@ pragma solidity ^0.8.0;

/// @title A contract that manages fee-related functionality.
interface ITreasuryManager {
/// @notice Sets the minting fee for a given token used for paying.
/// @notice Sets the minting fee forwarded to Guild's treasury.
/// @dev Callable only by the owner.
/// @param token The token whose fee is set.
/// @param newFee The new fee in base units.
function setFee(address token, uint256 newFee) external;
function setFee(uint256 newFee) external;

/// @notice Sets the address that receives the fees.
/// @dev Callable only by the owner.
/// @param newTreasury The new address of the treasury.
function setTreasury(address payable newTreasury) external;

/// @notice The minting fee of a token.
/// @param token The token used for paying.
/// @return fee The amount of the fee in base units.
function fee(address token) external view returns (uint256 fee);
function fee() external view returns (uint256 fee);

/// @notice Returns the address that receives the fees.
function treasury() external view returns (address payable);

/// @notice Event emitted when a token's fee is changed.
/// @param token The address of the token whose fee was changed. 0 for ether.
/// @notice Event emitted when the fee is changed.
/// @param newFee The new amount of fee in base units.
event FeeChanged(address token, uint256 newFee);
event FeeChanged(uint256 newFee);

/// @notice Event emitted when the treasury address is changed.
/// @param newTreasury The new address of the treasury.
Expand Down
24 changes: 0 additions & 24 deletions contracts/mock/MockBadERC20.sol

This file was deleted.

28 changes: 0 additions & 28 deletions contracts/mock/MockERC20.sol

This file was deleted.

8 changes: 4 additions & 4 deletions contracts/utils/TreasuryManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/I
contract TreasuryManager is ITreasuryManager, Initializable, OwnableUpgradeable {
address payable public treasury;

mapping(address token => uint256 fee) public fee;
uint256 public fee;
TomiOhl marked this conversation as resolved.
Show resolved Hide resolved

/// @notice Empty space reserved for future updates.
uint256[48] private __gap;
Expand All @@ -20,9 +20,9 @@ contract TreasuryManager is ITreasuryManager, Initializable, OwnableUpgradeable
treasury = treasury_;
}

function setFee(address token, uint256 newFee) external onlyOwner {
fee[token] = newFee;
emit FeeChanged(token, newFee);
function setFee(uint256 newFee) external onlyOwner {
fee = newFee;
emit FeeChanged(newFee);
}

function setTreasury(address payable newTreasury) external onlyOwner {
Expand Down
10 changes: 8 additions & 2 deletions docs/contracts/GuildPin.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ Sets metadata and the associated addresses.

```solidity
function claim(
address payToken,
struct IGuildPin.PinDataParams pinData,
address payable adminTreasury,
uint256 adminFee,
uint256 signedAt,
string cid,
bytes signature
Expand All @@ -128,8 +129,9 @@ The contract needs to be approved if ERC20 tokens are used.

| Name | Type | Description |
| :--- | :--- | :---------- |
| `payToken` | address | The address of the token that's used for paying the minting fees. 0 for ether. |
| `pinData` | struct IGuildPin.PinDataParams | The Guild-related data, see {PinDataParams}. |
| `adminTreasury` | address payable | The address where the pinned guild collects fees paid to them. |
| `adminFee` | uint256 | The fee to pay to the guild where the Pin is minted. |
| `signedAt` | uint256 | The timestamp marking the time when the data were signed. |
| `cid` | string | The cid used to construct the tokenURI for the token to be minted. |
| `signature` | bytes | The following signed by validSigner: pinData, signedAt, cid, chainId, the contract's address. |
Expand Down Expand Up @@ -303,6 +305,8 @@ function _authorizeUpgrade(
```solidity
function isValidSignature(
struct IGuildPin.PinDataParams pinData,
address payable adminTreasury,
uint256 adminFee,
uint256 signedAt,
string cid,
bytes signature
Expand All @@ -316,6 +320,8 @@ Checks the validity of the signature for the given params.
| Name | Type | Description |
| :--- | :--- | :---------- |
| `pinData` | struct IGuildPin.PinDataParams | |
| `adminTreasury` | address payable | |
| `adminFee` | uint256 | |
| `signedAt` | uint256 | |
| `cid` | string | |
| `signature` | bytes | |
Expand Down
22 changes: 4 additions & 18 deletions docs/contracts/interfaces/IGuildPin.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ function validSigner() external returns (address signer)

```solidity
function claim(
address payToken,
struct IGuildPin.PinDataParams pinData,
address payable adminTreasury,
uint256 adminFee,
uint256 signedAt,
string cid,
bytes signature
Expand All @@ -100,8 +101,9 @@ The contract needs to be approved if ERC20 tokens are used.

| Name | Type | Description |
| :--- | :--- | :---------- |
| `payToken` | address | The address of the token that's used for paying the minting fees. 0 for ether. |
| `pinData` | struct IGuildPin.PinDataParams | The Guild-related data, see {PinDataParams}. |
| `adminTreasury` | address payable | The address where the pinned guild collects fees paid to them. |
| `adminFee` | uint256 | The fee to pay to the guild where the Pin is minted. |
| `signedAt` | uint256 | The timestamp marking the time when the data were signed. |
| `cid` | string | The cid used to construct the tokenURI for the token to be minted. |
| `signature` | bytes | The following signed by validSigner: pinData, signedAt, cid, chainId, the contract's address. |
Expand Down Expand Up @@ -273,22 +275,6 @@ Error thrown when an incorrect amount of fee is attempted to be paid.
| paid | uint256 | The amount of funds received. |
| requiredAmount | uint256 | The amount of fees required for minting. |

### IncorrectPayToken

```solidity
error IncorrectPayToken(address token)
```

Error thrown when such a token is attempted to be used for paying that has no fee set.

_The owner should set a fee for the token to solve this issue._

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| token | address | The address of the token that cannot be used. |

### IncorrectSender

```solidity
Expand Down
18 changes: 3 additions & 15 deletions docs/contracts/interfaces/ITreasuryManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ A contract that manages fee-related functionality.

```solidity
function setFee(
address token,
uint256 newFee
) external
```

Sets the minting fee for a given token used for paying.
Sets the minting fee forwarded to Guild's treasury.

Callable only by the owner.

#### Parameters

| Name | Type | Description |
| :--- | :--- | :---------- |
| `token` | address | The token whose fee is set. |
| `newFee` | uint256 | The new fee in base units. |

### setTreasury
Expand All @@ -45,19 +43,11 @@ Callable only by the owner.
### fee

```solidity
function fee(
address token
) external returns (uint256 fee)
function fee() external returns (uint256 fee)
```

The minting fee of a token.

#### Parameters

| Name | Type | Description |
| :--- | :--- | :---------- |
| `token` | address | The token used for paying. |

#### Return Values

| Name | Type | Description |
Expand All @@ -77,18 +67,16 @@ Returns the address that receives the fees.

```solidity
event FeeChanged(
address token,
uint256 newFee
)
```

Event emitted when a token's fee is changed.
Event emitted when the fee is changed.

#### Parameters

| Name | Type | Description |
| :--- | :--- | :---------- |
| `token` | address | The address of the token whose fee was changed. 0 for ether. |
| `newFee` | uint256 | The new amount of fee in base units. |
### TreasuryChanged

Expand Down
Loading