<img src="https://i.imgur.com/oGJWIy6.png" alt="drawing" style="width:100px;margin: 30px 0 30px 0"/>
# PerfectPool Admin Guide
## PREP
### 1. Deploy new contracts
Make sure you are the admin of these contracts.
### 2. Copy-past their addresses into [airtable](https://airtable.com/tblJF6GCnyaUfISrv/viwfc6HeBKa9VSLNG?blocks=hide)
In [airtable](https://airtable.com/tblJF6GCnyaUfISrv/viwfc6HeBKa9VSLNG?blocks=hide) under the "contracts"-tab, paste each contract address in the row with the appropriate type (masterregistry,multisig etc.)

### 3. Hit the 'Refresh backend syncing service' button
- Go to the PerfectPool app url + "/admin", where you'll see the admin dashboard.
- Click the 'refresh'-button. This will connect the new contracts to the app via the back-end syncing script.
<img src="https://i.imgur.com/NZxn1pO.png" alt="drawing" style="width:500px;margin: 0px 0 50px 0"/>
----------------------
## CONTRACT ACTIVATION
### 3. Activate tournament on /admin
- Go to the url + "/admin", where you'll see the admin dashboard.
- Click the 'activate tournament'-button, next to the tournament's title.
- Sign the metamask tx
- If the tx is successfull, the status of the tournament will switch from 'Not activated' to 'Activated'
- Once a tournament is activated, users will be able to create pools and submit brackets to pools. They can do this until the startdate (to be set in section #4) of the tournament is reached.
### 4. Set a startdate on /admin
- Go to the url + "/admin"
- Select a startdate in the input and click the button
- Sign the metamask tx
- If the tx is succesfull, the status of the tournament will switch from 'Activated' to 'Activated - starts on [startdate]'
- Once the startdate is reached, pools are locked, no more submissions are possible, and the tournament will be displayed as the ongoing tournament on the home-page/view.

----------------------
## CONTRACT END & PAYOUT
### 5. Ending a tournament
- Go to the url + "/admin"
- Click the 'End Tournament'-button
- Sign the metamask tx
- If the tx is successfull, the status of the tournament will switch from 'Activated - starts on [startdate]' to 'Ended'
- Poolowners have 3 days after the enddate to accept or reject the tournament results
### 6. Payout
- A poolowner goes to his/her pool and accepts or rejects the results
- If a poolowner reject the results, the pool participants can instantly (after the reject tx is mined) claim their refund
- If a poolowner accept the results, the poolowner has to wait for 6 days to be able to proceed to calculating the winnings. This gives the pool participants the time to submit their token for scoring. **Tokens submitted AFTER a poolowner calculates winnings are not eligible to claim winnings.**
- If the poolowner has accepted, then 6 days after the tournament has ended, he/she can click the button to calculate the winnings
- Pool participants can now claim their winnings!
----------------------
## TIMELINE OVERVIEW

### PHASE 1:
The tournament is active, but not yet started:
- pools can be created
- brackets can be submitted
### PHASE 2:
The tournament is ongoing:
- no more pools can be created
- no more brackets can be submitted
### PHASE 3:
The tournament is done:
- **3.A:** within 3 days after end-date, pool-owners needs to accept/reject the tournament results. When he/she rejects, the participants of that pool can immediately claim refunds. When he/she accepts, participants must submit their token for scoring within 6 days.
- **3.B:**
- within 6 days after end-date, pool participants must have submitted their token for scoring. If not, their participation can not be scored.
- 6 days after end-date, pool owners can do the payout
----------------------
## ADMIN CHEATS
### ALL-SCORES-HACK
In a normal situation, admins can only click the "End tournament"-button when all matches of that tournament have been scored.
For testing purposes, there is a bypass for this in the code:
- in Admin.js, uncomment line 82 to 91
- in Admin.js, comment line 94 to 101
This will make the app act as if all matches have been scored, with the "second" (the one visually lowest in the bracket) team winning each time. Now you can end the tournament.

### TIME-JUMP
If you're working with the local setup, you can perform a time-jump to skip over the 6 days, making the pool-owners able to do the calculations+payout.
In your truffle-setup, first submit these two functions separately:
`function increaseTimeC(addSeconds) {web3.currentProvider.send({jsonrpc: "2.0", method: "evm_increaseTime", params: [addSeconds], id: 0}, console.log)}`
`web3.currentProvider.send({jsonrpc: "2.0", method: "evm_mine", params: [], id: 0}, console.log)`
It should look like this:

Now you can use that second function to jump in time 604800 seconds (=7days):
`increaseTimeC(604800)`