Skip to content

Commit ed6f024

Browse files
committed
Adding onchain interactions
1 parent 55a3f58 commit ed6f024

1 file changed

Lines changed: 107 additions & 10 deletions

File tree

erasurebay-docs/bay-overview.md

Lines changed: 107 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,125 @@
1-
# ErasureBay Overview
1+
# Erasure Protocol Docs
22

3-
ErasureBay is a dapp on the Erasure protocol. It’s a marketplace for information of any kind. It’s Numerai’s demonstration of the power of Erasure to improve the Web itself.
3+
## Erasure Bay
4+
ErasureBay is a dapp built upon the Erasure protocol. It’s a marketplace for buying/selling information of any kind. It’s Numerai’s demonstration of the power of Erasure to improve the Web itself.
45

56
**How it works**
6-
* Post data to storage that no one owns
7+
* Post data to storage that no one owns(ex: ipfs)
78
* Stake money on your claims. Encrypt them, then reveal them, to prove you knew something.
89
* Sell them under a smart contract that must be enforced.
910

10-
## Step by Step Walkthrough
11+
12+
### State Machine Architecture
13+
14+
Erasure uses shared registries to establish a single source of truth for the Erasure Protocol. So far, the registries developed are:
15+
16+
* Erasure_Agreements: To keep track of Griefing templates.
17+
* Erasure_Posts: To keep track of Feed and Post templates
18+
* Erasure_Users: To keep track of users and their data
19+
* Erasure_Escrows
20+
21+
**Clone Factories**
22+
23+
Using the Spawner library, every item on Erasure is created as a clone of a previously deployed template. We call these Clone Factories. Every clone is also registered in a registry which provides a single source of truth on the status of the protocol.
24+
25+
![](https://i.imgur.com/bEUAp0H.png)
26+
27+
**Staking**
28+
29+
![](https://i.imgur.com/JELJwhJ.png)
30+
31+
**Agreements**
32+
33+
When two parties decide to engage, they begin by staking NMR and agreeing on a set of conditions for punishment. We call this combination of skin in the game and rules of engagement an Erasure_Agreement.
34+
35+
> Griefing is an example of an Agreement which allows two parties to come to a resolution without a third party arbitrator through punishing one another at a cost.
36+
37+
Griefing has two main methods: `_grief()` and `setRatio`
38+
- `_grief` returns the cost of the punishment and is taken form the account of the punisher. Therefore requires appropriate ERC-20 token approval
39+
- `setRatio` Set the grief ratio and type for a given staker. The ratio represents the cost in NMR to burn 1 NMR of the counterparty.
40+
41+
**First example of Griefing is *SimpleGriefing***
42+
> SimpleGriefing agreement allows a staker to grant permission to a counterparty to punish, reward, or release their stake
43+
44+
![](https://i.imgur.com/w0ab7n7.png)
45+
46+
- increaseStake()
47+
Can be called by staker only to increase the stake
48+
49+
- reward()
50+
Called by the counterparty to increase the stake
51+
52+
- releaseStake()
53+
Called by the counterparty to release the stake to the staker
54+
55+
- punish()
56+
Called by the counterparty to punish the staker
57+
```js
58+
function punish(uint256 punishment, bytes memory message) public returns
59+
(uint256 cost) {
60+
// restrict access
61+
require(isCounterparty(msg.sender) || Operated.isOperator(msg.sender),
62+
"only counterparty or operator");
63+
64+
// execute griefing
65+
cost = Griefing._grief(msg.sender, _data.staker, punishment, message);
66+
}
67+
```
68+
`punishment`: amount of NMR (18 decimals) to be burned from the stake
69+
`message`: data to emit as event giving reason for the punishment
70+
71+
72+
**Second Example is *CountdownGriefing***
73+
> CountdownGriefing agreement allows a staker to grant permission to a counterparty to punish, reward, or release their stake until the countdown is completed.
74+
>
75+
![](https://i.imgur.com/DXy1lte.png)
76+
77+
It behaves similar to SimpleGriefing with an extra touch of a countdown.
78+
79+
`startCountdown`
80+
Called by the staker to begin countdown to finalize the agreement
81+
```js
82+
function startCountdown() public returns (uint256 deadline) {
83+
require(isStaker(msg.sender) || Operated.isOperator(msg.sender), "only
84+
staker or operator");
85+
86+
// require countdown is not started
87+
require(isInitialized(), "deadline already set");
88+
89+
// start countdown
90+
return Countdown._start();
91+
}
92+
```
93+
94+
**Countdown** makes use of block timestamps to determine start time and end time.
95+
`_start()` Starts the countdown based on the current block timestamp and returns `deadline` which is timestamp of the end of the countdown(current timestamp + countdown length)
96+
97+
Once the countdown is over, the stake can call `retrieveStake()` to retrieve the remaining stake as the agreement has ended.
98+
99+
**CountdownGriefingEscrow**
100+
This contract acts as escrow and allows for a buyer and a seller to deposit their stake and payment before sending it to a CountdownGriefing agreement.
101+
102+
This contract is designed such that there is only two end states: deposits are returned to the buyer and the seller OR the agreement is successfully created.
103+
![](https://i.imgur.com/89jQMVf.png)
104+
105+
We'll go into it's details below
106+
107+
### Step by Step Walkthrough
11108

12109
Let's see how erasure bay interacts with erasure protocol
13110

14-
### New User Registration
111+
**New User Registration**
15112

16113
- New User connects to Erasure Client. ErasureClient generates asymmetric encryption keys `PubKey`, `PrivKey`
17114
```js
18115
const keypair = ErasureHelper.crypto.asymmetric.generateKeyPair(sig, salt);
19116
```
20117

21-
- ErasureClient uploads `PubKey` to `Erasure_Users`
118+
- ErasureClient registers user to `Erasure_Users` and uploading it's data
22119
```js
23120
const ethers = require("ethers");
24121
const ErasureUsersArtifact = require("Erasure_Users.json");
25-
const user = PubKey;
122+
const user = keypair.publicKey; // Public Key
26123
const data = 16; //any data
27124

28125
// UserData in bytes
@@ -73,7 +170,7 @@ function getUserData(address user) public view returns (bytes memory data) {
73170
data = _metadata[user];
74171
}
75172
```
76-
### Creating a Post
173+
**Creating a Post**
77174
A Feed_Factory is a factory contract for managing feeds.
78175
- Seller first creates a `Feed` template contract from Feed_Factory by calling method `create`
79176

@@ -163,7 +260,7 @@ function _submitHash(bytes32 hash) internal {
163260
const metadataJsonIpfsPath = await ipfs.pinata.pinJSONToIPFS(metadata)
164261
const metadataHex = ErasureHelper.ipfs.hashToHex(metadataJsonIpfsPath)
165262
```
166-
### Selling a Post
263+
**Selling a Post**
167264

168265
Once the post is created, it's time to sell.
169266
- Seller creates `Escrow` using CountdownGriefingEscrow_Factory.create() with `calldata` as parameter. This is exactly same as creating a Feed Template as Feed_Factory and CountdownGriefingEscrow_Factory are both factory contracts and method `create` is a factory method.
@@ -325,4 +422,4 @@ function submitData(bytes memory data) public {
325422

326423
- Retrives
327424
- Computes
328-
### Revealing a Post
425+
**Revealing a Post**

0 commit comments

Comments
 (0)