Local Setup - maticnetwork/reddit-bakeoff-poc GitHub Wiki
To setup the repository and test out the scripts, you can either choose to test out the deployed contracts on Mumbai // Görli network or deploy your own set of contracts.
Test deployed contracts
All addresses for the deployed contracts can be found in mumbai.json file. The ones we'll be interacting with on both networks are:
Network: Mumbai
| Contract | Address (Mumbai) |
|---|---|
| SubredditPoints | 0xc4f93FeF8086c452134B0F15a5AE963ACe6A7748 |
| Distributions | 0xd7ab2634121e7afCE48b2A8Ea5db908869158D3E |
| Subscriptions | 0x94B8f2A9a36Be215F2D4211DFee523f204f0a897 |
Network: Görli
| Contract | Address (Görli) |
|---|---|
| SubredditPoints | 0x0e7e9e6Cc56F356e412F6b7CA63Da0a883243fC0 |
| MintableERC20Predicate | 0x54C39834035d32Fe785557E2c26016F1fFb4C3d4 |
| WithdrawManager (Proxy) | 0x2923C8dD6Cdf6b2507ef91de74F1d5E0F11Eac53 |
| FastExit | 0x8a7490Fc46885e0795051Af9a28A3852A988E34f |
| ExitNFT | 0xE2Ab047326B38e4DDb6791551e8d593D30E02724 |
Setup
Clone the repository
$ git clone https://github.com/maticnetwork/reddit-bakeoff-poc.git
$ cd reddit-bakeoff-poc
Install Dependencies
$ npm install
Add configurations
The scripts will look for owner account's private key inside /secrets.json. This owner account is the owner of Reddit's contracts for generating claim and funding randomly generated users for Gas.
The secrets.json should look something like this:
{
"privateKeys": {
"owner":""
}
}
Inside /config/default.json add Goerli network's RPC.
{
"dev": {
...
},
"mumbai": {
...
...
"parent": {
"rpc": "https://goerli.infura.io/v3/<GOERLI-API-KEY>"
},
...
}
}
Export environment variable
export NETWORK=mumbai
Run Tests (scripts)
1. test1.js Test minting, transferring and subscription (burning) of SubredditPoints Token Contract on Matic.
(Note: run the following command from the root of the directory)
$ node scripts/test1.js
What the script does: It generates 2 random user accounts: user1 and user2. The owner account signs a claim for user1 which is then submitted to mint some amount of tokens (the number of tokens is configurable here). User1 does a simple transfer of tokens to user2, and then performs a subscribe (burning tokens).
Network: These operations happen on Matic Network.
Function Calls:
2. test2.js Test initiation of withdraw from Matic (Matic -> Ethereum)
(Note: run the following command from the root of the directory)
$ node scripts/test2.js
What the script does: It generates 1 random user account: user1. The owner account signs a claim for user1 which is then submitted to mint some amount of tokens (the number of tokens is configurable here). User1 initiates a withdraw transaction on SubredditPoints.sol. The transaction hash is included in a block which needs to be checkpointed before user1 can claim their asset on Ethereum. (read: What are checkpoints?)
The script locally stores user's and transaction's information in a file /info.json to query for checkpoint inclusion and confirmation of withdraw later.
Matic's Javascript SDK is used in the scripts for withdraw operations.
Network: These operations happen on Matic Network.
Function Calls:
Helpers: To check for checkpoint inclusion
You can run
$ node scripts/helpers/checkpoint-inclusion
to query for the status of inclusion of your burnt transaction in a checkpoint.
You can also query for any specific block, like:
$ node scripts/helpers/checkpoint-inclusion <block-number>
3. test2-exit.js Confirmation of withdraw from Matic (Matic -> Ethereum)
(Note: run the following command from the root of the directory)
$ node scripts/test2-exit.js
What the script does: Once the checkpoint has went through (running node scripts/helpers/checkpoint-inclusion returns success), the user can confirm their exit from Matic. The script submits the burn transaction hash and to the predicate on Ethereum. (read: What are predicates?)
The confirmation of the transaction mints a new ExitNFT and transfer to the user. This ExitNFT can be used to claim the assets later. (read: What is ExitNFT?)
The script is dependent on test2.js and queries from the locally stored /info.json
Matic's Javascript SDK is used in the scripts for withdraw operations.
Network: These operations happen on Matic Network.
Function Calls:
startExitWithBurntTokenson MintableERC20Predicate.sol: This function internally calls WithdrawManager's addExitToQueue.
4. test3-plasma-exit.js Processing Exits after the Challenge Period ends
(Note: run the following command from the root of the directory)
$ node scripts/test3-plasma-exit.js
What the script does: A user with a valid ExitNFT in their account can claim their tokens after the Challenge Period ends (read: What is Challenge Period?). The script calls processExits on WithdrawManager.sol, effectively burning the ExitNFT and minting the tokens into owner's account.
The script is dependent on test2.js and queries from the locally stored /info.json
Note: processExits can be called by anyone with enough funds.
Matic's Javascript SDK is used in the scripts for withdraw operations.
Network: These operations happen on Gorli Test Network (Ethereum).
Function Calls:
processExitson WithdrawManager.sol: This function internally calls MintableERC20Predicate's onFinalizeExit.
5. test4-fast-exit.js Processing Exits bypassing the Challenge Period
(Note: run the following command from the root of the directory)
$ node scripts/test4-fast-exit.js
What the script does: A user with a valid ExitNFT in their account can swap their tokens (with a valid signature) from the FastExit contract to instantly receive their assets on Main network.
The script is dependent on test2.js and queries from the locally stored /info.json
Matic's Javascript SDK is used in the scripts for withdraw operations.
Network: These operations happen on Gorli Test Network (Ethereum).
Function Calls:
swapon FastExit.sol