---
# System prepended metadata

title: ⚔️ WPOKT BackEnd Scoping Document  ⚔️
tags: [WPOKT, ' proposal']

---

---
tags: WPOKT, POKT, Pocket, proposal
title: ⚔️ WPOKT BackEnd Scoping Document  ⚔️
---

# WPOKT BackEnd Scoping Document 

Develop a system that can facilitate the minting of wPOKT tokens upon receiving POKT tokens on the Pocket network to a designated address. The system should also enable the return of POKT tokens upon burning wPOKT tokens on the Ethereum Mainnet.
 
## Stack
 - [Copper Unlimited Online](https://docs.copper.co/#how-to-launch) - signing txs using [MPC](https://copper.co/insights/market-insights/copper-enhances-key-management-with-mpc)
 - Golang - watcher nodes
 - Mongodb Database

## Architecture

- The "wPOKT node" will be composed of two services running concurrently on a single server: the Watcher node, which monitors events on both blockchains and performs subsequent actions, and the Signer node, which utilizes the Copper Unlimited Online service for signing transactions to move funds to and from the Copper Vault.
- To ensure security, the wPOKT Nodes will be deployed on a Virtual Private Cloud (VPC) on AWS with limited network connectivity. Specifically, they will not have any incoming network connections to minimize the overall attack surface.
- Each wPOKT node will be responsible for holding a [shard](https://copper.co/insights/market-insights/copper-unlimited-or-how-and-why-were-destroying-private-keys-updated) of the private key that controls the POKT tokens within the Copper Vault. 
- We can further enhance this distribution by deploying each node on varied AWS regions, which can help to minimize the risk of data center failures by spreading the nodes across multiple geographic locations.
- To ensure a secure distribution of key shards, we will employ a total of 12 key shards, requiring a minimum of 9 shards to be present in order to complete each transaction. Thus, at any point there would be 12 active wPOKT nodes.


![](https://hackmd.io/_uploads/BkyR8wLN3.png)

## Specs

- Each wPOKT node will have 4 active threads:
    1. Monitor POKT transfers txs + create mint entry
    2. Monitor active mints + sign and execute them
    3. Monitor burn transactions + create burn entry
    4. Monitor active burns + sign and execute them
- The first two threads together manage the mint flow whereas the last two threads manage the burn flow.
- Each node has a local state of latest block scanned for both pocket and ethereum networks.

### Mint Flow

#### I.  Monitor POKT transfers txs + create mint entry w/ unit tests - 16hrs

- It will actively monitor POKT transactions on the Pocket network that contain a specific memo and a transfer to the Copper Vault. 
- Monitoring will start from the last block scanned as per local state, starting from a "startBlock" until the latest block. 
- Upon noticing such transactions it creates a mint entry in the database:
```
type Order struct {
    // Details of an external copper order
}

type Mint struct {
    TransactionHash   string
    Block             uint32
    Confirmations     uint32
    FromAddress       string
    ToAddress         string
    Amount            uint64
    CreatedAt         time.Time
    UpdatedAt         time.Time
    Status            string 
    Signers           []string
    Order             *Order
}
```

- Entry can be created by any of the 12 watcher nodes. We shall ensure that only one of them is successful in creating this by having an index in the database to ensure only one entry is created per transaction hash from a particular user and a particular amount.

#### II. Monitor active mints + sign and execute them w/ unit tests

- It will be monitoring the database for new mint entries. Upon finding such entries it shall act based on the status of the entry:
    - `detected` 
        - check block confirmations and update the db with the number of confirmations, if it is greater than a stipulated value then update the status to `confirmed`
    - `confirmed` 
        - create a [smart-call order](https://docs.copper.co/#create-smart-call-order) on Copper to mint wPOKT on Mainnet and update the status to `started` and also stores order details
    - `started` 
        - sends a local api call to Copper Unlimited to add a partial signature to the active order and adds its hostname to the list of signers in the mint entry. 
        - if the number of signers is greater than 9, then mark the entry as `signed`
    - `signed`
        - check the status of order on copper and mark as `executed` if successful

### Burn flow

#### III. Monitor burn transactions + create burn entry w/ unit tests

- It will actively monitor actively monitor wPOKT burn transactions on the Ethereum network. 
- Monitoring will start from the last block scanned as per local state, starting from a "startBlock" until the latest block. 
- Upon noticing such transactions it creates a burn entry in the database:
```
type Order struct {
    // Details of an external copper order
}

type Burn struct {
    TransactionHash   string
    Block             uint32
    Confirmations     uint32
    FromAddress       string
    ToAddress         string
    Amount            uint64
    CreatedAt         time.Time
    UpdatedAt         time.Time
    Status            string 
    Signers           []string
    Order             *Order
}
```

- Entry can be created by any of the 12 watcher nodes. We shall ensure that only one of them is successful in creating this by having an index in the database to ensure only one entry is created per transaction hash from a particular user and a particular amount.


#### IV. Monitor active burns + sign and execute them w/ unit tests

- It will be monitoring the database for new burn entries. Upon finding such entries it shall act based on the status of the entry:
    - `detected` 
        - check block confirmations and update the db with the number of confirmations, if it is greater than a stipulated value then update the status to `confirmed`
    - `confirmed` 
        - create a [withdraw order](https://docs.copper.co/#create-withdraw-order) on Copper to transfer the corresponding amount of POKT from the Copper Vault to the specified recipient address.
    - `started` 
        - sends a local api call to Copper Unlimited to add a partial signature to the active order and adds its hostname to the list of signers in the mint entry. 
        - if the number of signers is greater than 9, then mark the entry as `signed`
    - `signed`
        - check the status of order on copper and mark as `executed` if successful

### Testing & Deployment

- End to end testing
- User testing 
- Testnet & mainnet deployment

## Considerations

- To display the status of user transactions, the frontend using nextJS API should have read-only credentials to access the MongoDB database.
- We have ensured the security and stability of our system by using Copper and Copper Unlimited as the core, as they are well-audited and considered to be highly secure.
- The structure of the mint and burn entries may undergo changes as necessary during the development process.
