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

Contract updates to match new frontends #28

Merged
merged 44 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
23269e9
Dont mix postId and threadId, use only postId
T-Damer May 25, 2023
44a1866
Add indexed sender to addPost/addComment and increment number properly
T-Damer May 25, 2023
b73605b
Propely check lastPost for pin/unPin
T-Damer May 25, 2023
9bd9ce4
use old require function
T-Damer May 25, 2023
6c5f3c7
use sender instead of author to don't mix the fields
T-Damer May 25, 2023
a00e634
Add more info to pin post error
smyzin May 25, 2023
8b7e3f0
Remove sender from comment event
smyzin May 25, 2023
5eb85a9
0.2.6-0
smyzin May 25, 2023
7c47090
remove unused CID import
T-Damer May 25, 2023
dd3059a
Merge branch 'use-postId' of github.com:BigWhaleLabs/obss-storage-con…
T-Damer May 25, 2023
6578b43
Mark visibility explicitly
T-Damer May 25, 2023
8c9f41b
Remove temp `onlyAllowedCaller`
smyzin May 25, 2023
61b6193
Merge branch 'use-postId' of github.com:BigWhaleLabs/obss-storage-con…
smyzin May 25, 2023
f0eaeee
0.2.6-1
smyzin May 25, 2023
c2dfc4a
Fix pinning to feeds
smyzin May 25, 2023
c5b3b71
0.2.6-2
smyzin May 25, 2023
71d29e5
Correct reaction removal, now Reaction also has reactionId connected …
T-Damer May 26, 2023
bf236ce
Merge branch 'use-postId' of github.com:BigWhaleLabs/obss-storage-con…
T-Damer May 26, 2023
3f6ee02
0.2.7-0
T-Damer May 26, 2023
7d217b2
place increment in proper place
T-Damer May 26, 2023
95e6f08
Automatically add contract to targets
T-Damer May 26, 2023
c0a3e10
Fix replies & remove one unnecessary check
smyzin May 26, 2023
c728982
0.2.7-1
smyzin May 26, 2023
6219432
The contract will delete reaction if needed on AddReaction
T-Damer May 29, 2023
6fd4839
Add basic feeds automatically
T-Damer May 29, 2023
be42919
Add info about network before deploy
T-Damer May 31, 2023
bb2dfcf
Pass proper argument
T-Damer May 31, 2023
da71b9f
hopefully fix access to comments array
T-Damer May 31, 2023
636f578
For getReactions as well
T-Damer May 31, 2023
e7eca9b
Give a comment why there's -1
T-Damer May 31, 2023
b02d486
Check if post was already pinned/unpinned
T-Damer Jun 1, 2023
283a7b1
Remove default export names
T-Damer Jun 5, 2023
b106341
revert names and give a proper comment
T-Damer Jun 5, 2023
a888e7f
only author
T-Damer Jun 5, 2023
590dd00
update easy comments
T-Damer Jun 5, 2023
3836f9b
fix building
backmeupplz Jun 5, 2023
efb6c30
Merge branch 'use-postId' of github.com:backmeupplz/obss-storage-cont…
backmeupplz Jun 5, 2023
7b46064
fix remove reaction
backmeupplz Jun 5, 2023
85ce8f0
bring back the necessary check
backmeupplz Jun 5, 2023
6287bd6
change reactions
backmeupplz Jun 5, 2023
bc1fc43
revert parentPost change
backmeupplz Jun 5, 2023
139463f
remove incrementing number of comments for comments
backmeupplz Jun 5, 2023
a9a63e4
correct script
T-Damer Jun 5, 2023
a6cae04
simplify deploy script
T-Damer Jun 5, 2023
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
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ ETHERSCAN_API_KEY=0000000000000000000000000000000000000000
ETH_RPC=https://example.com/rpc
CONTRACT_OWNER_PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000000
COINMARKETCAP_API_KEY=0000000000000000000000000000000000000000
GSN_PAYMASTER_CONTRACT=0x0000000000000000000000000000000000000000
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ The main storage contract made specially for [Big Whale Labs projects](https://g

## Environment variables

| Name | Description |
| ---------------------------- | --------------------------------------------------------- |
| `ETHERSCAN_API_KEY` | Etherscan API key |
| `ETH_RPC` | Ethereum RPC URL |
| `CONTRACT_OWNER_PRIVATE_KEY` | Private key of the contract owner to deploy the contracts |
| `COINMARKETCAP_API_KEY` | Coinmarketcap API key |
| Name | Description |
| ---------------------------- | --------------------------------------------------------------------------------------------- |
| `ETHERSCAN_API_KEY` | Etherscan API key |
| `ETH_RPC` | Ethereum RPC URL |
| `CONTRACT_OWNER_PRIVATE_KEY` | Private key of the contract owner to deploy the contracts |
| `COINMARKETCAP_API_KEY` | Coinmarketcap API key |
| `GSN_PAYMASTER_CONTRACT` | Paymaster contract to add deployed OBSS into targets automatically, defaults to BWL constants |

Also check out the `.env.sample` file for more information.

## Available scripts

- `yarn build` — compiles the contract ts interface to the `typechain` directory
- `yarn test` — runs the test suite
- `yarn deploy` — deploys the contract to the network
- `yarn deploy` — deploys the contract to the network. After deploying go to blockchain scanner address in the console and verify your contract as proxy to use it
- `yarn eth-lint` — runs the linter for the solidity contract
- `yarn lint` — runs all the linters
- `yarn prettify` — prettifies the code in th project
- `yarn release` — relases the `typechain` directory to NPM
- `yarn release` — releases the `typechain` directory to NPM
5 changes: 3 additions & 2 deletions contracts/OBSSStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ contract OBSSStorage is OwnableUpgradeable, ERC2771Recipient {
Karma public karma;
Profiles public profiles;
Feeds public feeds;
mapping(uint => mapping(uint => mapping(uint => mapping(address => bool)))) karmaGranted;
mapping(uint => mapping(uint => mapping(uint => mapping(address => bool))))
public karmaGranted;

// Constructor
function initialize(
Expand Down Expand Up @@ -137,7 +138,7 @@ contract OBSSStorage is OwnableUpgradeable, ERC2771Recipient {
}

function pinOrUnpinFeedPost(uint feedId, uint postId, bool pin) public {
profiles.pinOrUnpinPost(_msgSender(), feedId, postId, pin);
feeds.pinOrUnpinPost(_msgSender(), feedId, postId, pin);
}

function addBatchFeedPosts(PostRequest[] memory postRequests) public {
Expand Down
1 change: 1 addition & 0 deletions contracts/models/Reaction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ struct Reaction {
uint postId;
uint commentId;
uint8 reactionType;
uint reactionId;
backmeupplz marked this conversation as resolved.
Show resolved Hide resolved
uint value;
}
2 changes: 0 additions & 2 deletions contracts/models/ReactionRequests.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "./CID.sol";

struct AddReactionRequest {
uint feedId;
uint postId;
Expand Down
43 changes: 31 additions & 12 deletions contracts/superclasses/Posts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ contract Posts is KetlGuarded {
public usersToReactions;

// Events
event PostAdded(uint indexed feedId, uint indexed postId, Post post);
event PostAdded(
uint indexed feedId,
uint indexed postId,
Post post,
address indexed author
);
event PostPinned(uint indexed feedId, uint indexed postId);
event PostUnpinned(uint indexed feedId, uint indexed postId);
event CommentAdded(
Expand Down Expand Up @@ -153,7 +158,7 @@ contract Posts is KetlGuarded {
participants[feedId][currentPostId].push(sender);
participantsMap[feedId][currentPostId][sender] = true;
// Emit the event
emit PostAdded(feedId, lastPostIds[feedId].current(), post);
emit PostAdded(feedId, lastPostIds[feedId].current(), post, sender);
// Increment current post id
lastPostIds[feedId].increment();
}
Expand Down Expand Up @@ -240,8 +245,10 @@ contract Posts is KetlGuarded {
require(parentPost.author != address(0), "Post not found");
// Fetch parent comment and check if it exists
if (replyTo > 0) {
Post memory parentComment = comments[feedId][postId][replyTo];
require(parentComment.author != address(0), "Comment not found");
require(
comments[feedId][postId][replyTo - 1].author != address(0),
"Comment not found"
);
}
// Increment comment id (so that we start with 1)
lastCommentIds[feedId][postId].increment();
Expand Down Expand Up @@ -323,31 +330,43 @@ contract Posts is KetlGuarded {
// Fetch post or comment
Post memory post = commentId == 0
? posts[feedId][postId]
: comments[feedId][postId][commentId];
: comments[feedId][postId][commentId - 1]; // comments start with 1
// Check if post or comment exists
require(post.author != address(0), "Post or comment not found");
// Get old reaction if it exists
Reaction memory oldReaction = usersToReactions[feedId][postId][commentId][
sender
];
// Check if reaction already exists
require(oldReaction.sender == address(0), "Reaction already exists");
require(
oldReaction.reactionType != reactionType,
"Reaction of this type already exists"
);
if (oldReaction.reactionType != 0) {
removeReaction(
sender,
RemoveReactionRequest(feedId, postId, commentId, oldReaction.reactionId)
);
}
// Get lastReactionIds
uint reactionId = lastReactionIds[feedId][postId][commentId].current();
// Create reaction
Reaction memory reaction = Reaction(
sender,
feedId,
postId,
commentId,
reactionType,
reactionId,
msg.value
);
// Add reaction
reactions[feedId][postId][commentId].push(reaction);
// Remember the reaction for user
usersToReactions[feedId][postId][commentId][sender] = reaction;
// Increment reaction id
// Increment lastReactionId
lastReactionIds[feedId][postId][commentId].increment();
// If ether was sent, transfer it to the author
// If ether was sent, transfer it to the sender
if (msg.value > 0) {
Address.sendValue(payable(post.author), msg.value);
}
Expand All @@ -358,7 +377,7 @@ contract Posts is KetlGuarded {
postId,
commentId,
reactionType,
lastReactionIds[feedId][postId][commentId].current(),
reactionId,
msg.value
);
}
Expand All @@ -367,7 +386,7 @@ contract Posts is KetlGuarded {
address sender,
RemoveReactionRequest memory reactionRequest
)
external
public
onlyAllowedCaller
onlyKetlTokenOwners(sender)
onlyAllowedFeedId(reactionRequest.feedId)
Expand All @@ -379,7 +398,7 @@ contract Posts is KetlGuarded {
// Fetch post or comment
Post memory post = commentId == 0
? posts[feedId][postId]
: comments[feedId][postId][commentId];
: comments[feedId][postId][commentId - 1]; // comments start with 1
// Check if post or comment exists
require(post.author != address(0), "Post or comment not found");
// Check if sent by the owner
Expand All @@ -402,7 +421,7 @@ contract Posts is KetlGuarded {
// Fetch post or comment
Post memory post = commentId == 0
? posts[feedId][postId]
: comments[feedId][postId][commentId];
: comments[feedId][postId][commentId - 1]; // comments start with 1
// Check if post or comment exists
require(post.author != address(0), "Post or comment not found");
// Get the number of reactions
Expand Down
11 changes: 9 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import '@typechain/hardhat'
import 'hardhat-gas-reporter'
import 'solidity-coverage'
import * as dotenv from 'dotenv'
import { ETH_RPC as FALLBACK_ETH_RPC } from '@big-whale-labs/constants'
import {
ETH_RPC as FALLBACK_ETH_RPC,
GSN_MUMBAI_PAYMASTER_CONTRACT_ADDRESS,
} from '@big-whale-labs/constants'
import { HardhatUserConfig } from 'hardhat/config'
import { cleanEnv, str, testOnly } from 'envalid'

dotenv.config()

const {
export const {
CONTRACT_OWNER_PRIVATE_KEY,
ETH_RPC,
ETHERSCAN_API_KEY,
COINMARKETCAP_API_KEY,
GSN_PAYMASTER_CONTRACT,
} = cleanEnv(process.env, {
CONTRACT_OWNER_PRIVATE_KEY: str({
devDefault: testOnly(
Expand All @@ -24,6 +28,9 @@ const {
ETH_RPC: str({ default: FALLBACK_ETH_RPC }),
ETHERSCAN_API_KEY: str({ devDefault: testOnly('') }),
COINMARKETCAP_API_KEY: str({ devDefault: testOnly('') }),
GSN_PAYMASTER_CONTRACT: str({
default: GSN_MUMBAI_PAYMASTER_CONTRACT_ADDRESS,
}),
})

const config: HardhatUserConfig = {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@big-whale-labs/obss-storage-contract",
"version": "0.2.5-0",
"version": "0.2.7-1",
"description": "Storage contract for OBSS",
"repository": {
"type": "git",
Expand Down Expand Up @@ -76,6 +76,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@big-whale-labs/constants": "^0.1.85",
"@big-whale-labs/gsn-paymaster-contract": "^0.1.1",
"@big-whale-labs/ketl-attestation-token": "^0.0.10",
"@openzeppelin/contracts-upgradeable": "^4.8.3",
"@openzeppelin/hardhat-upgrades": "^1.26.0",
Expand Down
Loading