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

Permissionless staking contract - Staker #24

Merged
merged 66 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
95ceece
Added hardhat-docgen as a dependency
zomglings Jul 10, 2024
087db3f
Removed hardhat-docgen
zomglings Jul 10, 2024
d653fe7
Put package-lock.json in .gitignore
zomglings Jul 10, 2024
6693f84
Started working on Staker contract
zomglings Jul 11, 2024
e524fc1
Added a bunch of tests for pool creation and configuration
zomglings Jul 11, 2024
0389e83
Complete tests for pool creation and admin functionality
zomglings Jul 11, 2024
ada5d3d
Added test for creation with unknown token type
zomglings Jul 11, 2024
d092c98
Don't want to use 0 for NATIVE_TOKEN_TYPE
zomglings Jul 11, 2024
38bde03
[WIP] Starting to add actual staking/unstaking mechanic
zomglings Jul 11, 2024
bc34226
Greated "game7 staker" CLI
zomglings Jul 11, 2024
eaf792b
Completed first draft of Staker
zomglings Jul 12, 2024
5b90b14
Improved one of the initiateUnstake tests
zomglings Jul 12, 2024
6bf75e2
Added tokenURI override
zomglings Jul 12, 2024
14a8b7c
Image URI TODO
zomglings Jul 12, 2024
1508433
Upated Staker bindings
zomglings Jul 12, 2024
9c81c19
Restricted transfers of position tokens...
zomglings Jul 12, 2024
6cae0bc
Nerdsniped on managing flow labels
zomglings Jul 17, 2024
94509d6
Applied "graffiti number" to staker.md
zomglings Jul 17, 2024
7f1fcbf
More staker flows
zomglings Jul 17, 2024
01ff815
Numbered staker flows
zomglings Jul 17, 2024
bcef75e
Flows to prevent unstake without cooldown before lockup expiration...
zomglings Jul 17, 2024
aa8be04
Numbering
zomglings Jul 17, 2024
82ed300
Updated flows to cover unstaking with cooldown behavior
zomglings Jul 17, 2024
c9e4faf
Numbering of flows
zomglings Jul 17, 2024
b317724
Flow headings
zomglings Jul 17, 2024
b90aaad
Added two flows
zomglings Jul 17, 2024
69c091b
ADded two new flows
zomglings Jul 17, 2024
65d7c92
Added more tests
zomglings Jul 17, 2024
e56867c
STAKER-24 test
zomglings Jul 17, 2024
312453a
Renamed FindLabels* to ParseLabels* in graffiti
zomglings Jul 17, 2024
121ced3
Started adding unstaking tests...
zomglings Jul 17, 2024
503fc70
STAKER-27 test
zomglings Jul 17, 2024
e1ad91c
STAKER-28 test
zomglings Jul 17, 2024
20c75d3
STAKER-29, STAKER-30, STAKER-31, STAKER-32 tests
zomglings Jul 17, 2024
d447898
Tests for...
zomglings Jul 18, 2024
379f692
Tests for STAKER-{49..52}
zomglings Jul 18, 2024
045d6a9
Fixed label on test for STAKER-40
zomglings Jul 18, 2024
f801f58
More staker tests
zomglings Jul 18, 2024
c8fc976
Fixed cooldown bug
zomglings Jul 19, 2024
2a3b655
Updated unstake time checks
zomglings Jul 19, 2024
3832806
Clarifying comments
zomglings Jul 19, 2024
807cd40
Making good progress on tests
zomglings Jul 20, 2024
8a09f3b
Split the Staker test file into two files
zomglings Jul 20, 2024
57a2bba
Almost there
zomglings Jul 20, 2024
5126196
Added tests for all documented execution flows!
zomglings Jul 20, 2024
d5279d1
Added execution flows to be tested for position metadata
zomglings Jul 20, 2024
4227564
Updated Staker bindings
zomglings Jul 20, 2024
fb06567
Touched up metadata tests
zomglings Jul 20, 2024
b15561b
Slight updated to main README
zomglings Jul 20, 2024
ca99e9d
Merge branch 'main' into feature/staking
zomglings Jul 20, 2024
0f7b659
Added operational script for setup of Staker contract on Game7 testnet
zomglings Jul 21, 2024
891f6cd
Clarified transferability of pool 0 on Game7 testnet
zomglings Jul 21, 2024
63f3da0
Updated script to show staking/unstaking of native token
zomglings Jul 21, 2024
c2dbcbc
Added tests for `CurrentAmountInPool` and `CurrentPositionsInPool`.
zomglings Jul 22, 2024
37b59c2
Added more flows to test
zomglings Jul 22, 2024
25d6d5e
One more flow to test
zomglings Jul 22, 2024
33220a0
Added "game7 mock" commands
zomglings Jul 24, 2024
89aa85d
Added test for STAKER-119
zomglings Jul 24, 2024
b6c01c1
Added more tests
zomglings Jul 25, 2024
8667259
Added two more execution flows
zomglings Jul 25, 2024
d09559c
More Staker tests
zomglings Jul 25, 2024
63fb9ce
All tests
zomglings Jul 25, 2024
df88356
Fixed tests for 0 amounts
zomglings Jul 25, 2024
d674d84
README changes
zomglings Jul 30, 2024
a98dac1
Updated Makefile and regenerated bindings
zomglings Jul 30, 2024
36268ce
Some more information in readme
zomglings Jul 30, 2024
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
47 changes: 36 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
.PHONY: clean generate regenerate test docs redocs hardhat bindings
.PHONY: clean generate regenerate test docs redocs hardhat bindings test-graffiti test-web3 clean-web3 deepclean

build: hardhat bindings bin/game7
build: hardhat bindings bin/game7 bin/graffiti

rebuild: clean generate build

bin/game7:
mkdir -p bin
go build -o bin/game7 ./cmd/game7

bin/graffiti:
mkdir -p bin
go build -o bin/graffiti ./cmd/graffiti

bindings/ERC20/ERC20.go: hardhat
mkdir -p bindings/ERC20
seer evm generate --package ERC20 --output bindings/ERC20/ERC20.go --hardhat web3/artifacts/contracts/token/ERC20.sol/ERC20.json --cli --struct ERC20
Expand All @@ -20,18 +24,39 @@ bindings/WrappedNativeToken/WrappedNativeToken.go: hardhat
mkdir -p bindings/WrappedNativeToken
seer evm generate --package WrappedNativeToken --output bindings/WrappedNativeToken/WrappedNativeToken.go --hardhat web3/artifacts/contracts/token/WrappedNativeToken.sol/WrappedNativeToken.json --cli --struct WrappedNativeToken

bindings: bindings/ERC20/ERC20.go bindings/TokenFaucet/TokenFaucet.go bindings/WrappedNativeToken/WrappedNativeToken.go
bindings/Staker/Staker.go: hardhat
mkdir -p bindings/Staker
seer evm generate --package Staker --output bindings/Staker/Staker.go --hardhat web3/artifacts/contracts/staking/Staker.sol/Staker.json --cli --struct Staker

bindings/MockERC20/MockERC20.go: hardhat
mkdir -p bindings/MockERC20
seer evm generate --package MockERC20 --output bindings/MockERC20/MockERC20.go --hardhat web3/artifacts/contracts/mock/tokens.sol/MockERC20.json --cli --struct MockERC20

bindings/MockERC721/MockERC721.go: hardhat
mkdir -p bindings/MockERC721
seer evm generate --package MockERC721 --output bindings/MockERC721/MockERC721.go --hardhat web3/artifacts/contracts/mock/tokens.sol/MockERC721.json --cli --struct MockERC721

bindings/MockERC1155/MockERC1155.go: hardhat
mkdir -p bindings/MockERC1155
seer evm generate --package MockERC1155 --output bindings/MockERC1155/MockERC1155.go --hardhat web3/artifacts/contracts/mock/tokens.sol/MockERC1155.json --cli --struct MockERC1155

bindings: bindings/ERC20/ERC20.go bindings/TokenFaucet/TokenFaucet.go bindings/WrappedNativeToken/WrappedNativeToken.go bindings/Staker/Staker.go bindings/MockERC20/MockERC20.go bindings/MockERC721/MockERC721.go bindings/MockERC1155/MockERC1155.go

test:
npx hardhat test
test-web3:
cd web3 && npx hardhat test

test-graffiti:
go test ./cmd/graffiti -v

test: test-web3 test-graffiti

clean:
rm -rf bindings/ERC20/* bin/* bindings/TokenFaucet/* bindings/WrappedNativeToken/*
rm -rf bindings/ERC20/* bin/* bindings/TokenFaucet/* bindings/WrappedNativeToken/* bindings/Staker/* bindings/MockERC20/* bindings/MockERC721/* bindings/MockERC1155/*

hardhat:
cd web3 && npm install && npx hardhat compile
clean-web3:
rm -rf web3/node_modules web3/artifacts

docs:
forge doc
deepclean: clean clean-web3

redocs: clean docs
hardhat:
cd web3 && npm install && npx hardhat compile
79 changes: 72 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,77 @@

The Game 7 Protocol is a comprehensive mono repository that includes all the essential components for the Game 7 ecosystem. This repository consolidates the frontend, backend, and web3 components required to run and interact with the Game 7 Protocol.

## Repository Structure
## What this repository contains

- **frontend**: This directory contains the codebase for the user interface of the Game 7 Protocol. Built with modern web technologies, it offers a seamless and intuitive user experience.

- **backend**: This directory houses the server-side logic, including APIs, database management, and other essential backend services. It ensures robust and secure data handling for the protocol.

- **web3**: This directory includes all the web3 components, such as smart contracts, that power the Game 7 Protocol. These contracts are written in Solidity and are responsible for the decentralized logic of the game, ensuring transparency and security.
The [`G7DAO/protocol`](https://github.com/G7DAO/protocol) repository contains the smart contracts that make up
the Game7 protocol.

- **cmd**: This directory contains the command-line interface (CLI) for the Game 7 Protocol. It provides a convenient way to interact with the protocol from the command line.
It also contains:

1. Go bindings to these contracts
2. The `game7` command line tool which can be used to deploy and interact with these contracts
3. Some tools, like `graffiti`, which are used in the process of developing and testing the Game7 protocol

## The Game7 protocol

### The G7 token

[Implementation of the Game7 ERC20 token](./web3/contracts/token/ERC20.sol)

This token will be deployed on Ethereum mainnet. The implementation consists of slight modifications to
the wrapped Ether contract, [`WETH9`](https://github.com/gnosis/canonical-weth/blob/master/contracts/WETH9.sol).

### Staker

- [Implementation of the Game7 `Staker`](./web3/contracts/staking/Staker.sol)
- [Execution flows used to test the `Staker`](./web3/flows/staker.md)
- Staker test files: [1](./web3/test/Staker.test.1.ts), [2](./web3/test/Staker.test.1.ts), [3](./web3/test/Staker.test.1.ts)

The `Staker` is a permissionless staking contract that can be used by anybody.

Anyone can create staking pools which accept either one of:
1. The native token of the chain the `Staker` is deployed to
2. Tokens from an ERC20 contract
3. Tokens from an ERC721 contract
4. Tokens with a fixed token ID from an ERC1155 contract

Once a pool has been created, anyone can open positions under that staking pool by transferring tokens to the `Staker`.
Positions are represented by ERC721 tokens on the `Staker` contract.

Each pool has the following parameters:
1. Whether positions opened under that staking pool (represented by ERC721 tokens) are transferable.
2. The lockup period for positions opened under that pool - i.e. the number of seconds before the tokens
can be unstaked.
3. The cooldown period for positions opened under that pool - i.e. the number of seconds after a user
initiates an unstake that they have to wait before they can complete the unstake operation and receive
their staked tokens.

Pool administrators can change any of these parameters at any time. To make a pool immutable, we recommend
transferring administration of that pool to the zero address.


## Development

### Requirements

- [Node.js](https://nodejs.org/en) (version >= 20)
- [`hardhat`](https://github.com/NomicFoundation/hardhat), which we used to build and test our smart contracts
- [Go](https://go.dev/) (version >= 1.21), for the `game7` CLI, and other developmental and operational tools
- [`seer`](https://github.com/moonstream-to/seer), which we use to generate Go bindings and command-line interfaces


### Building and testing this code

The [`Makefile`](./Makefile) for this project can be used to build all the code in the repository.

Build everything using:

```bash
make
```

To run all tests for all the code in this repository:

```bash
make test
```
Loading
Loading