Skip to content

Commit

Permalink
find unregistered @types
Browse files Browse the repository at this point in the history
find these types is straighforward, register them at runtime will
probably be challenging...
  • Loading branch information
tbruyelle committed Apr 21, 2024
1 parent e3c0b41 commit 4f0633d
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 5 deletions.
49 changes: 45 additions & 4 deletions signtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"encoding/json"
"fmt"
"os"
"slices"

"github.com/davecgh/go-spew/spew"

txtypes "github.com/cosmos/cosmos-sdk/types/tx"
)
Expand All @@ -14,11 +17,49 @@ func signTx(unsignedTxFile string) error {
return err
}
defer f.Close()
var rawTx struct {
Body struct {
Messages []map[string]any
}
}
if err := json.NewDecoder(f).Decode(&rawTx); err != nil {
return fmt.Errorf("JSON decode %s: %v", unsignedTxFile, err)
}
var types []string
for _, msg := range rawTx.Body.Messages {
findUnregisteredTypes(msg, &types)
}
fmt.Println("TODO: NEED TO REGISTER THESE TYPES", types)
var tx txtypes.Tx
// NOTE: Unsurprisingly doesn't work with legacy encoding/json
if err := json.NewDecoder(f).Decode(&tx); err != nil {
return err
if _, err := f.Seek(0, 0); err != nil {
return fmt.Errorf("seek %s: %v", unsignedTxFile, err)
}
fmt.Println(tx)
if err := unmarshaler.Unmarshal(f, &tx); err != nil {
return fmt.Errorf("unmarshal tx: %v", err)
}
spew.Dump(tx)
return nil
}

func findUnregisteredTypes(m map[string]any, types *[]string) {
for k, v := range m {
if k == "@type" {
typeURL := v.(string)
if _, err := registry.Resolve(typeURL); err != nil {
if !slices.Contains(*types, typeURL) {
// type not registered, add to the list
*types = append(*types, typeURL)
}
}
continue
}
switch x := v.(type) {
case []map[string]any:
for _, m := range x {
findUnregisteredTypes(m, types)
}
case map[string]any:
findUnregisteredTypes(x, types)
}
}
}
47 changes: 47 additions & 0 deletions testdata/gaia-bank-tx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"body": {
"messages": [
{
"@type": "/cosmos.bank.v1beta1.MsgSend",
"from_address": "cosmos1k8e50d2d8xkdfw9c4et3m45llh69e7xzw6uzga",
"to_address": "cosmos1kp8wl9t99azqdf8qnhjku606wtzna04rkasp9a",
"amount": [
{
"denom": "uatom",
"amount": "1000"
}
]
},
{
"@type": "/cosmos.bank.v1beta1.MsgSend",
"from_address": "cosmos1k8e50d2d8xkdfw9c4et3m45llh69e7xzw6uzga",
"to_address": "cosmos1kp8wl9t99azqdf8qnhjku606wtzna04rkasp9a",
"amount": [
{
"denom": "uatom",
"amount": "1000"
}
]
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "ugovgen",
"amount": "50000"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
43 changes: 43 additions & 0 deletions testdata/govgen-gov-tx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"body": {
"messages": [
{
"@type": "/govgen.gov.v1beta1.MsgSubmitProposal"
},
{
"@type": "/govgen.gov.v1beta1.MsgSubmitProposal",
"content": {
"@type": "/govgen.gov.v1beta1.TextProposal",
"title": "Equitable ATONE Distribution in the Spirit of AtomOne's Founding Principles",
"description": "# Proposal 001: Equitable ATONE Distribution in the Spirit of AtomOne's Founding Principles\n\n## Changelog\n\n* March 13th 2024: first draft\n* March 14th 2024: add data and code\n* March 21st 2024: update distribution to ensure non-voters do not exceed 1/3 of ATONE supply\n* March 21st 2024: reduce the final supply by a factor of 10.\n* March 28th 2024: update the base multiplier for *No* and *NWV* votes to x9\n\n## Status\n\nDraft\n\n## Summary\n\nThis proposal seeks to establish a fair and principled distribution mechanism for\nATONE, the native token of AtomOne, reflecting the foundational principles as\noutlined in the AtomOne [founding documents](https://github.com/atomone-hub/genesis).\nThe proposal tries to synthesize the [discussion](https://github.com/atomone-hub/genesis/issues/12)\naround the ATONE distribution, and leveraging the snapshot from Cosmos Hub's\n[proposal 848](https://www.mintscan.io/cosmos/proposals/848), it aims to reward\nparticipation and engagement while adhering to AtomOne's ethos of intelligent\ndistribution and governance.\n\n## Context\n\nAtomOne's inception was driven by fundamental disagreements within the Cosmos\nHub's community, particularly regarding the nature of ATOM as a staking versus\nmonetary token and the broader vision for the network's future\n[1](https://github.com/atomone-hub/genesis/blob/main/README.md)\n[2](https://github.com/atomone-hub/genesis/blob/main/STAKING_VS_MONEY.md).\nProposal 848's passage, advocating for ATOM's \"*halving*\" without adequately\naddressing security concerns, marked a pivotal moment that underscored the\nnecessity for AtomOne. AtomOne is thus not merely a technical divergence but\nrather a philosophical stand for a network that remains true to the principles\nof minimalism in its IBC/ICS hub functionality, robust security model, and an\nintelligent, aligned community governance structure.\n\n## Decision\n\nIn accordance with AtomOne's foundational principles and the discussions\nsurrounding the token distribution, we propose the ATONE distribution mechanism\noutlined below, reflecting a balanced approach to reward participation,\nengagement, and alignment with AtomOne's vision. The intent of the distribution\nmechanism is to *increase* the percentage ownership in the network for the *NO*\nand *No With Veto* (NWV) votes on proposal 848, but to also ensures that the\npercentage ownership of the non-voting categories does not exceed a fixed 1/3\nof the total supply. A decimation factor is also applied at the end to reduce\nthe total supply by a factor of 10.\n\n**Note that, in addition, it is proposed that the ICF will be entirely slashed**.\n\n> [!NOTE]\n> We specifically refer to the *ATOM that voted* on proposal 848, and not\n> accounts, to accurately reflect how the distribution mechanism will work,\n> which also mirrors in practice how the `x/gov` tally works on the Cosmos Hub.\n> The final balance for each account will be the result of the contributions\n> from each ATOM with which the account either voted (and how), or did not.\n\n> [!NOTE]\n> In the context of this proposal, the term *voting* ATOM is intended to refer\n> to ATOM that was used to vote on proposal 848 either directly or indirectly\n> via delegation. A *non-voting* ATOM is ATOM that was not used to vote either\n> directly or indirectly because the validator it is delegated to also did not\n> vote.\n\n> [!IMPORTANT]\n> The following proposed mechanism does not explicitly account for the `K = 0.1`\n> decimation factor. This factor is considered implicit as it will be applied\n> indiscriminately alongside any other category-specific multiplier\n\n1. **YES Votes to Proposal 848**: standard 1x multiplier for the ATOM that\n voted *YES* at the snapshot.\n\n2. **NO and NWV Votes to Proposal 848**: \n 1. Acknowledged with a 8x multiplier on top of the ATOM that voted *NO* and\n *NWV*, emphasizing the critical stance against the monetary token proposition\n and alignment with AtomOne's security philosophy. The resulting balance will\n essentially be 9x the original ATOM balance.\n\n 2. Plus, the ATOM that voted *NWV* will also get a 3% bonus on top in\n order to (slightly) reward the stronger political stance.\n\n3. **ABSTAIN Votes to Proposal 848**: Assigned a multiplier `C` that ensures\n that the total percentage ownership of the *Abstain*, *Did Not Vote* (DNV)\n and *Not Staked* categories does not exceed a target percentage `t` of 1/3:\n ```math\n C = (t / (1 - t)) * ((y + 9n + 9nwv) / (a + dnv + u))\n ```\n where:\n - `C` is the multiplier to be found\n - `t` is the target percentage for the *non-voting* categories, which is *33%*.\n - `y` represents the total ATOM that voted *Yes*\n - `a` represents the total ATOM that voted *Abstain*\n - `n` represents the total ATOM that voted *No*\n - `nwv` represents the total ATOM that voted *No With Veto*\n - `dnv` represents the total ATOM that *Did Not Vote*\n - `u` represents the total ATOM that *Unbonded* (*Not Staked*)\n\n4. **Did not vote (DNV) on Proposal 848**: It is considered to be *non-voting*\n the ATOM that did not vote at all (even through its delegations). The ATOM\n that *DNV* get the same multiplier as ATOM that voted *Abstain*, but they\n incur in an additional 3% malus to (slightly) punish inactivity.\n\n5. **Unbonded ATOM (Not Staked)**: will equate to the *non-voting* category and\n receive the same multiplier as ATOM that *DNV*.\n\n> [!NOTE]\n> An account that has voted indirectly through its delegations may see its\n> balance affected by different multipliers depending on the votes of its\n> delegations.\n> The same reasoning applies in the case of *weighted* votes.\n> Moreover, it is always the case that for any account that has both bonded as\n> well as unbonded ATOM, the resulting ATONE balance will come from the\n> contribution of each part as already discussed.\n\nThe following table is also provided for a quick recap:\n\n| | DNV | YES | ABSTAIN | NO | NWV |\n|---------------------|-----------|-----|---------|----|-----------|\n| Bonded multiplier | C x malus | 1 | C | 9 | 9 x bonus |\n| Unbonded multiplier | C x malus | - | - | - | - |\n\nAccompanying code that implements the proposed distribution mechanism is\navailable at [https://github.com/atomone-hub/govbox](https://github.com/atomone-hub/govbox). Please refer to the \n[PROP-001.md](https://github.com/atomone-hub/govbox/blob/master/PROP-001.md)\ndocument for a more detailed breakdown and further details on code, data and\napplied formulae.\nTo obtain the final distribution, we also apply a decimation factor `K = 0.1`\nwhen computing balances.\nAccording to the current calculations - which **may** change - the potential\nATONE distribution will be of approximately ~97 Millions.\n\n| | TOTAL | DID NOT VOTE | YES | NO | NOWITHVETO | ABSTAIN | NOT STAKED |\n|--------------------|------------|--------------|-----------|------------|------------|-----------|------------|\n| ATONE Distributed | 96,997,800 | 10,445,719 | 6,374,676 | 48,015,988 | 10,780,005 | 5,672,466 | 15,708,946 |\n| *% Ownership* | | 11% | 7% | 50% | 11% | 6% | 16% |\n| *% ATOM prop 848* | | 20% | 21% | 16% | 3% | 10% | 30% |\n\n- The proposed ATONE supply is ~1/7 of the ATOM supply at the time of proposal 848.\n- The `C` multiplier is computed as ~1,620.\n- The ICF slashing represents a total of 12,677,878 ATOM\n\n> [!WARNING]\n> While we have explained and detailed the proposed methodology, we cannot\n> guarantee the accuracy of reliability of any of the accompanying code and \n> resulting preliminary data. Although every effort has been made to ensure\n> accuracy and reliability, there is no guarantee that the tools will remain\n> unchanged or error-free as further developments occur. Voters should exercise\n> caution and discretion when utilizing these tools, and understand that any\n> information or calculations provided by them are subject to revision.\n\nWe acknowledge there are additional details to be discussed for the final ATONE\ndistribution, such as for example [issue #13](https://github.com/atomone-hub/genesis/issues/13)\nfrom the AtomOne genesis repo, but these are intentionally left out of this\nproposal as it seeks to establish a baseline distribution mechanism.\n\n## Consequences\n\n* Establishes a fair and structured token distribution mechanism that aligns \n with AtomOne's founding ethos.\n\n* Sets a precedent for future endeavors, demonstrating the importance \n of community alignment and shared values in token distribution decisions.\n\n## Alternatives\n\nThe methodology proposed here was discussed and revised through multiple rounds\nbased on community feedback during the \n[GovGen Townhalls](https://github.com/atomone-hub/genesis/tree/main/GovGen_Townhalls). \nShould this proposal fail to reach approval from the community, alternative\ndistribution mechanisms might be discussed and used instead. We did not evaluate\nalternative mechanisms as part of this proposal, but the proposal methodology\nwas revised based on community feedback during the\n[GovGen Townhalls](https://github.com/atomone-hub/genesis/tree/main/GovGen_Townhalls).\n\n## Governance votes\n\n* **YES**: You support the outlined ATONE distribution mechanism, recognizing\n the importance of aligning with AtomOne's core values and principles.\n* **NO**: You do not support the proposed distribution mechanism and advocate for\n an alternative approach.\n* **NO WITH VETO**: You strongly oppose the proposal due to perceived inequities\n or deviations from AtomOne's foundational principles.\n* **ABSTAIN**: You prefer to contribute to quorum without endorsing or opposing\n the proposal directly.\n"
},
"initial_deposit": [
{
"denom": "ugovgen",
"amount": "5000000000"
}
],
"proposer": "govgen12anjnnyqr7c0pdgvwmdcwe0r8xx8l0n4kwk2n6"
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "ugovgen",
"amount": "50000"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
Loading

0 comments on commit 4f0633d

Please sign in to comment.