owned this note
owned this note
Published
Linked with GitHub
# Risk Prediction Module
*Written in Pythonic pseudocode, mapped from a simulation model. This document serves as a guide for implementation. In all cases, SDK code language, structure, and implementation requirements should supercede, with the caveat that the algorithmic property is not compromised.*
## Concept
The risk prediction module is a mechanism to obtain information about the perception of an associated variable through crowdsourcing.
![Risk Prediction Block Diagram](https://i.imgur.com/G1t2Qul.png)
In this case, holders of an associated token may attest in the positive or negative as a reflection of their belief in the risk variable, $\alpha$.
## State
**Risk Prediction Global State**
State necessary to maintain legal state of the risk prediction module.
| Name| Schema |
|-----|----------|
| Risk_Prediction| Dict |
| Variable Name | Variable Type | Definition|
|-----|----------|----|
|Claims_0 | uint64 | Number of attestations against $\alpha$ |
|Supply_0 | uint64 | Tokens bonded to attest against $\alpha$ |
|Claims_1 | uint64 | Number of attestations in favor of $\alpha$ |
|Supply_1 | uint64 | Tokens bonded to attest in favor of $\alpha$ |
|I_Invariant| Invariant| Risk Prediction Curve Invariant |
|kappa, $\kappa$ | sdk.Dec | Multiplicative Inverse of Reserve Ratio |
|Price | uint64 | Price associated with the Risk Prediction Curve |
|alpha, $\alpha$ |sdk.Dec | Risk factor being attested |
**Agent State**
State necessary to maintain legal state of agents interacting with the risk prediction module.
| Name| Schema |
|-----|----------|
| Agent_Risk_Prediction| Dict |
| Variable Name | Variable Type | Definition|
|-----|----------|----|
|Address| address | Agent address |
|PubKey | pubkey | Agent Public Key |
|claims_0 | uint64 | Number of attestations against $\alpha$ |
|supply_0 | uint64 | Tokens an agent attests against $\alpha$ |
|claims_1 | uint64 | Number of an agent attests in favor of $\alpha$
|supply_1 | uint64 | Tokens an agent attests in favor of $\alpha$ |
|supply_free | uint64 | Tokens an agent holds unattested |
**Input State**
Hook input to Risk Prediction Module from Bonding Curve Module
| Variable Name | Variable Type | Definition|
|-----|----------|----|
|Bonding_Curve| address | Module address |
|PubKey | pubkey | Module Public Key |
|Supply | uint64 | Total tokens outstanding |
|Reserve | uint64 | Reserve amount in Bonding Curve |
Hook input to Risk Prediction Module from Outcomes Based Funding Module
| Variable Name | Variable Type | Definition|
|-----|----------|----|
|Outcomes_Funding| address | Module address |
|PubKey | pubkey | Module Public Key |
|Commitment | uint64 | Commitment to Pay Outcome of Project |
|alpha, $\alpha$ | sdk.Dec | Risk factor being attested |
|Reserve | uint64 | Reserve amount in Bonding Curve |
**Output State**
Hook output to Bonding Curve Module
Bonding_Curve Update State
| Name| Schema |
|-----|----------|
| Bonding_Curve| Dict |
| Variable Name | Variable Type | Definition|
|-----|----------|----|
|Bonding_Curve| address | Module address |
|PubKey | pubkey | Module Public Key |
|kappa, $\kappa$ | sdk.Dec | Multiplicative Inverse of Reserve Ratio |
|Price | uint64 | Price associated with the Risk Prediction Curve |
|alpha, $\alpha$ | sdk.Dec | Risk factor being attested |
## Parameters
The nature of the Risk Prediction Module is not reliant centralized updates and parametric control from a governance module. It ideally serves as a dual repository of attested tokens. Thus, the parameter set is exclusively limited to the intialized values of the global state.
| Name| Schema |
|-----|----------|
| Initial_Parameter_Set| Dict_struct |
| Variable Name | Variable Type | Definition|
|-----|----------|----|
|Initial_Supply_0 | uint64 | Starting Tokens in the attest against $\alpha$ pool |
|Initial_Supply_1 | uint64 | Starting Tokens in the attest in favor of $\alpha$ pool |
|Initial_I_Invariant| Invariant| Starting Risk Prediction Curve Invariant |
|Initial_kappa, $\kappa$ | sdk.Dec | Starting Multiplicative Inverse of Reserve Ratio |
|Initial_Price | uint64 | Starting Price associated with the Risk Prediction Curve |
|Initial_alpha, $\alpha$ | sdk.Dec | Starting Risk factor being attested |
From the governing module, in this the Outcome-Based Funding Module, the reserve amount and commitment to pay upon completion are required parameters for this module.
| Name| Schema |
|-----|----------|
| Outcome-Based_Parameter_Set| Dict_struct |
| Variable Name | Variable Type | Definition|
|-----|----------|----|
|Commitment | uint64 | Commitment to pay upon successful completion |
## Initialization
Initialization of the Risk Prediction Module contains the Initial Parameter Set to create the first legal state.
| Name| Schema |
|-----|----------|
| Initial_Parameter_Set| Dict_struct |
|Risk_Prediction_Module| address | Module address |
|PubKey | pubkey | Module Public Key |
## State Transitions
Updates to the global state of the Risk Prediction Module occur upon resolution of a block under which there is a positive or a negative attestation.
For a positive attestation, the following function will update the global state:
```
def Global_State_Update_Positive_Attestation( Global_State, MsgAttestPositive)
alpha = Risk_Prediction['alpha']
R = Risk_Prediction['reserve']
Q = Risk_Prediction['attestations_1'] + Risk_Prediction['attestations_0']
Q1 = Risk_Prediction['attestations_1']
Q0 = Risk_Prediction['attestations_0']
S = Risk_Prediction['supply']
S1 = Risk_Prediction['supply_1']
S0 = Risk_Prediction['supply_0']
I = Risk_Prediction['invariant_I']
q1 = MsgAttestPositive['agent_attestations_1']
q0 = MsgAttestPositive['agent_attestations_0']
s_free = MsgAttestPositive['agent_supply_free']
s1 = MsgAttestPositive['agent_supply_1']
s0 = MsgAttestPositive['agent_supply_0']
def update_Q1():
Q1 = Q1 + MsgAttestPositive['agent_attestations_1']
return 'attestations_1', Q1
def update_S1():
S1 = S1 + MsgAttestPositive['agent_supply_1']
return 'supply_1', S1
def update_alpha():
new_alpha = S1 * R / (S1 * R - S0 * R + S0*C)
return new_alpha
def update_kappa():
kappa = I / (I - (C*new_alpha))
return 'kappa', kappa
#### Hook to BC ###########
def update_V():
V = (S**(kappa))/R
return 'invariant_V', V
#### Hook to BC ###########
#### Hook to BC ###########
def update_Price():
P = kappa * (R/S)
return 'Price', P
#### Hook to BC ###########
return Risk_Prediction
```
For a negative attestation, the following function will update the global state:
```
def Global_State_Update_Negative_Attestation( Global_State, MsgAttestNegative)
alpha = Risk_Prediction['alpha']
R = Risk_Prediction['reserve']
Q = Risk_Prediction['attestations_1'] + Risk_Prediction['attestations_0']
Q1 = Risk_Prediction['attestations_1']
Q0 = Risk_Prediction['attestations_0']
S = Risk_Prediction['supply']
S1 = Risk_Prediction['supply_1']
S0 = Risk_Prediction['supply_0']
I = Risk_Prediction['invariant_I']
q1 = MsgAttestNegative['agent_attestations_1']
q0 = MsgAttestNegative['agent_attestations_0']
s_free = MsgAttestNegative['agent_supply_free']
s1 = MsgAttestNegative['agent_supply_1']
s0 = MsgAttestNegative['agent_supply_0']
def update_Q0():
Q0 = Q0 + MsgAttestNegative['agent_attestations_0']
return 'attestations_0', Q0
def update_S0():
S0 = S0 + MsgAttestNegative['agent_supply_0']
return 'supply_0', S0
def update_alpha():
new_alpha = S1 * R / (S1 * R - S0 * R + S0*C)
return new_alpha
def update_kappa():
kappa = I / (I - (C*new_alpha))
return 'kappa', kappa
#### Hook to BC ###########
def update_V():
V = (S**(kappa))/R
return 'invariant_V', V
#### Hook to BC ###########
#### Hook to BC ###########
def update_Price():
P = kappa * (R/S)
return 'Price', P
#### Hook to BC ###########
return Risk_Prediction
```
For a positive attestation, the following function will update the agent state:
```
def Agent_State_Update_Positive_Attestation( Agent_State, MsgAttestPositive)
q1 = MsgAttestPositive['agent_attestations_1']
q0 = MsgAttestPositive['agent_attestations_0']
s_free = MsgAttestPositive['agent_supply_free']
s1 = MsgAttestPositive['agent_supply_1']
s0 = MsgAttestPositive['agent_supply_0']
def update_q1():
q1 = q1 + MsgAttestPositive['agent_attestations_1']
return 'attestations_1', q1
def update_s1():
s1 = s1 + MsgAttestPositive['agent_supply_1']
return 'supply_1', S1
def update_s_free():
s_free = s_free - MsgAttestPositive['agent_supply_1']
return s_free
return Agent_State
```
For a negative attestation, the following function will update the agent state:
```
def Agent_State_Update_Negative_Attestation( Agent_State, MsgAttestNegative)
q1 = MsgAttestNegative['agent_attestations_1']
q0 = MsgAttestNegative['agent_attestations_0']
s_free = MsgAttestNegative['agent_supply_free']
s1 = MsgAttestNegative['agent_supply_1']
s0 = MsgAttestNegative['agent_supply_0']
def update_q0():
q0 = q0 + MsgAttestNegative['agent_attestations_0']
return 'attestations_0', q0
def update_s0():
s0 = s0 + MsgAttestNegative['agent_supply_0']
return 'supply_0', S0
def update_s_free():
s_free = s_free - MsgAttestNegative['agent_supply_0']
return s_free
return Agent_State
```
## Messages
`Agent Action Space`
An agent may attest with their tokens positively or negatively in the Risk Prediction Module.
MsgAttestPositive
```
def MsgAttestPositive(PublicKey, Address, Agent_State):
get PublicKey
get Address
q1 = Agent_State['agent_attestations_1']
s1 = Agent_State['agent_supply_1']
return MsgAttestPositive
```
MsgAttestNegative
```
def MsgAttestNegative(PublicKey, Address, Agent_State):
get PublicKey
get Address
q0 = Agent_State['agent_attestations_0']
s0 = Agent_State['agent_supply_0']
return MsgAttestNegative
```
## Events
`Tracing agent action execution`
Resolution of an attestation, either negative or postive, will trigger an update to the Global State of the Risk Prediction Module. This update is necessary for the Bonding Curve Module and the instantiating Outcomes Based Funding Module
```
def Global_State_Update(Global_State)
return Risk_Prediction
```
An agent or explorer would require execution tracing of messages and thus would need agent state information.
## Handler
`Permissible Agent Action Determination Posterior`
For either attestation, confirmation of existence of tokens is necessary.
```
def Checksum(PublicKey, Address, Agent_State, Message_Supply):
get PublicKey
get Address
attested_tokens = Message_Supply['supply_tokens']
if attested_tokens > Agent_State['agent_supply_free:
FAIL
return CheckSum
```
Batching of attestation messages may be necessary for processing transactions. In this case, an aggregation of attestations should be performed.
```
def Batch_attestations(PublicKey, Address, Agent_State, MsgAttestNegative, MsgAttestPositive):
get PublicKey
get Address
for MsgAttestNegative in messages:
negative_attested_tokens += Message_Supply['agent_supply_0']
for MsgAttestPositive in messages:
positive_attested_tokens += Message_Supply['agent_supply_1']
return negative_attested_tokens, positive_attested_tokens
```
## Keepers
`Permissible Control Action Determination Prior`
| Name| Schema |
|-----|----------|
| Initial_Parameter_Set| Dict_struct |
|Risk_Prediction_Module| address | Module address |
|PubKey | pubkey | Module Public Key |
The Risk Prediction Module in its essence is a place for agents to express their belief about an associated module. Thus, there is little need for centralized control over the specific mechanisms within this module. The controls necessary at this level are to initialize the module, and the authority to pause (with the option to close activity), unpause activity.
For initialization:
```
def Initiate_Module(Initial_Parameter_Set, Risk_Prediction_Module, PubKey):
return Global_State
```
For pause or close activity:
```
def Pause_Module(Risk_Prediction_Module, PubKey):
return Pause_Phase
```
For unpause or close activity:
```
def Unpause_Module(Risk_Prediction_Module, PubKey, Global_State):
return Global_State
```
## Query
`Available Prescribed State Computation`
The end-user in the Risk Prediction Module would want to get the current published alpha.
```
def Query_Alpha(PublicKey, Address, Global_State):
get PublicKey
get Address
alpha = Global_State['alpha']
return alpha
```
The end-user in the Risk Prediction Module would want to compute the expected in change in alpha, given their prospective attestation of tokens and a direction of attestation, positive or negative.
```
def Query_Realized_Alpha(PublicKey, Address, _input):
get PublicKey
get Address
alpha = Global_State['alpha']
tokens_to_attest = _input
realized_alpha = f(alpha, tokens_to_attest, attest_direction)
return realized_alpha
```
## Querier
`Call on a Query`
Calls on a Query that an end-user could make are referenced here.
```
def get_alpha(PublicKey, Address):
get PublicKey
get Address
alpha = Query_Alpha()
return alpha
```
```
def get_realized_alpha(PublicKey, Address, tokens_to_attest):
get PublicKey
get Address
Query_Realized_Alpha = Query_Realized_Alpha(tokens_to_attest)
return Query_Realized_Alpha
```
## Hooks
`Module Interface`
An update to the Global State of the Risk Prediction Module should trigger an update to the sibling Bonding Curve Module. Specifically, to retrieve updated values of kappa and alpha.
```
BondingCurveCall
```
```
def get_Global_State_Update(Global_State)
return kappa, alpha
```
The parent Outcomes Based Funding Module will also need to monitor updates to the Global State of the Risk Prediction Module.
```
OutcomesBasedFundingCall
```
```
def get_Global_State_Update(Global_State)
return kappa, alpha
```