|
1 | | -# ErasureBay Overview |
2 | | - |
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. |
| 1 | +# Erasure Bay |
| 2 | +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. |
4 | 3 |
|
5 | 4 | **How it works** |
6 | | -* Post data to storage that no one owns |
| 5 | +* Post data to storage that no one owns(ex: ipfs) |
7 | 6 | * Stake money on your claims. Encrypt them, then reveal them, to prove you knew something. |
8 | 7 | * Sell them under a smart contract that must be enforced. |
9 | 8 |
|
10 | | -## Step by Step Walkthrough |
| 9 | + |
| 10 | +### State Machine Architecture |
| 11 | + |
| 12 | +Erasure uses shared registries to establish a single source of truth for the Erasure Protocol. So far, the registries developed are: |
| 13 | + |
| 14 | +* Erasure_Agreements: To keep track of Griefing templates. |
| 15 | +* Erasure_Posts: To keep track of Feed and Post templates |
| 16 | +* Erasure_Users: To keep track of users and their data |
| 17 | +* Erasure_Escrows |
| 18 | + |
| 19 | +**Clone Factories** |
| 20 | + |
| 21 | +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. |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +**Staking** |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +**Agreements** |
| 30 | + |
| 31 | +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. |
| 32 | + |
| 33 | +> 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. |
| 34 | +
|
| 35 | +Griefing has two main methods: `_grief()` and `setRatio` |
| 36 | +- `_grief` returns the cost of the punishment and is taken form the account of the punisher. Therefore requires appropriate ERC-20 token approval |
| 37 | +- `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. |
| 38 | + |
| 39 | +**First example of Griefing is *SimpleGriefing*** |
| 40 | +> SimpleGriefing agreement allows a staker to grant permission to a counterparty to punish, reward, or release their stake |
| 41 | +
|
| 42 | + |
| 43 | + |
| 44 | +- increaseStake() |
| 45 | +Can be called by staker only to increase the stake |
| 46 | + |
| 47 | +- reward() |
| 48 | +Called by the counterparty to increase the stake |
| 49 | + |
| 50 | +- releaseStake() |
| 51 | +Called by the counterparty to release the stake to the staker |
| 52 | + |
| 53 | +- punish() |
| 54 | +Called by the counterparty to punish the staker |
| 55 | +```js |
| 56 | +function punish(uint256 punishment, bytes memory message) public returns |
| 57 | +(uint256 cost) { |
| 58 | + // restrict access |
| 59 | + require(isCounterparty(msg.sender) || Operated.isOperator(msg.sender), |
| 60 | + "only counterparty or operator"); |
| 61 | + |
| 62 | + // execute griefing |
| 63 | + cost = Griefing._grief(msg.sender, _data.staker, punishment, message); |
| 64 | +} |
| 65 | +``` |
| 66 | +`punishment`: amount of NMR (18 decimals) to be burned from the stake |
| 67 | +`message`: data to emit as event giving reason for the punishment |
| 68 | + |
| 69 | + |
| 70 | +**Second Example is *CountdownGriefing*** |
| 71 | +> CountdownGriefing agreement allows a staker to grant permission to a counterparty to punish, reward, or release their stake until the countdown is completed. |
| 72 | +> |
| 73 | + |
| 74 | + |
| 75 | +It behaves similar to SimpleGriefing with an extra touch of a countdown. |
| 76 | + |
| 77 | +`startCountdown` |
| 78 | +Called by the staker to begin countdown to finalize the agreement |
| 79 | +```js |
| 80 | +function startCountdown() public returns (uint256 deadline) { |
| 81 | + require(isStaker(msg.sender) || Operated.isOperator(msg.sender), "only |
| 82 | + staker or operator"); |
| 83 | + |
| 84 | + // require countdown is not started |
| 85 | + require(isInitialized(), "deadline already set"); |
| 86 | + |
| 87 | + // start countdown |
| 88 | + return Countdown._start(); |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +**Countdown** makes use of block timestamps to determine start time and end time. |
| 93 | +`_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) |
| 94 | + |
| 95 | +Once the countdown is over, the stake can call `retrieveStake()` to retrieve the remaining stake as the agreement has ended. |
| 96 | + |
| 97 | +**CountdownGriefingEscrow** |
| 98 | +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. |
| 99 | + |
| 100 | +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. |
| 101 | + |
| 102 | + |
| 103 | +We'll go into it's details below |
| 104 | + |
| 105 | +### Step by Step Walkthrough |
11 | 106 |
|
12 | 107 | Let's see how erasure bay interacts with erasure protocol |
13 | 108 |
|
14 | | -### New User Registration |
| 109 | +**New User Registration** |
15 | 110 |
|
16 | 111 | - New User connects to Erasure Client. ErasureClient generates asymmetric encryption keys `PubKey`, `PrivKey` |
17 | 112 | ```js |
18 | 113 | const keypair = ErasureHelper.crypto.asymmetric.generateKeyPair(sig, salt); |
19 | 114 | ``` |
20 | 115 |
|
21 | | -- ErasureClient uploads `PubKey` to `Erasure_Users` |
| 116 | +- ErasureClient registers user to `Erasure_Users` and uploading it's data |
22 | 117 | ```js |
23 | 118 | const ethers = require("ethers"); |
24 | 119 | const ErasureUsersArtifact = require("Erasure_Users.json"); |
25 | | -const user = PubKey; |
| 120 | +const user = keypair.publicKey; // Public Key |
26 | 121 | const data = 16; //any data |
27 | 122 |
|
28 | 123 | // UserData in bytes |
@@ -73,7 +168,7 @@ function getUserData(address user) public view returns (bytes memory data) { |
73 | 168 | data = _metadata[user]; |
74 | 169 | } |
75 | 170 | ``` |
76 | | -### Creating a Post |
| 171 | +**Creating a Post** |
77 | 172 | A Feed_Factory is a factory contract for managing feeds. |
78 | 173 | - Seller first creates a `Feed` template contract from Feed_Factory by calling method `create` |
79 | 174 |
|
@@ -163,7 +258,7 @@ function _submitHash(bytes32 hash) internal { |
163 | 258 | const metadataJsonIpfsPath = await ipfs.pinata.pinJSONToIPFS(metadata) |
164 | 259 | const metadataHex = ErasureHelper.ipfs.hashToHex(metadataJsonIpfsPath) |
165 | 260 | ``` |
166 | | -### Selling a Post |
| 261 | +**Selling a Post** |
167 | 262 |
|
168 | 263 | Once the post is created, it's time to sell. |
169 | 264 | - 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 +420,4 @@ function submitData(bytes memory data) public { |
325 | 420 |
|
326 | 421 | - Retrives |
327 | 422 | - Computes |
328 | | -### Revealing a Post |
| 423 | +**Revealing a Post** |
0 commit comments