Skip to content

Tgrade home

Hannu edited this page Dec 7, 2022 · 21 revisions

Tgrade technologies used

Rust language for the cosmwasm smart contracts.
Typescript with React for the dApp.
Go Language for the blockchain.
We have open sourced the Tgrade dapp (written in Typescript using the Cosmos SDK) as a professional example of a front-end UI available here a recent and more elegant solution to connect a wallet would be to use Cosmos kit even if not included in the Tgrade dapp at this time.

Learning Resources

If you are comfortable with Rust and want to start writing smart contracts Cosmwasm has an academy that teaches you just that, for free! check availability here, or just view the documentation if you are starting from scratch the best place to learn about the Rust language is reading "The Book"

Upgrade guide

To upgrade Tgrade please review the following documentation & scripts: Upgrade Guide

API Reference

Table of Contents

Top

confio/globalfee/v1beta1/genesis.proto

GenesisState

GenesisState - initial state of module

Field Type Label Description
params Params Params of this module

Params

Params defines the set of module parameters.

Field Type Label Description
minimum_gas_prices cosmos.base.v1beta1.DecCoin repeated Minimum stores the minimum gas price(s) for all TX on the chain. When multiple coins are defined then they are accepted alternatively. The list must be sorted by denoms asc. No duplicate denoms or zero amount values allowed. For more information see https://docs.cosmos.network/master/modules/auth/01_concepts.html

Top

confio/globalfee/v1beta1/query.proto

QueryMinimumGasPricesRequest

QueryMinimumGasPricesRequest is the request type for the Query/MinimumGasPrices RPC method.

QueryMinimumGasPricesResponse

QueryMinimumGasPricesResponse is the response type for the Query/MinimumGasPrices RPC method.

Field Type Label Description
minimum_gas_prices cosmos.base.v1beta1.DecCoin repeated

Query

Query defines the gRPC querier service.

Method Name Request Type Response Type Description HTTP Verb Endpoint
MinimumGasPrices QueryMinimumGasPricesRequest QueryMinimumGasPricesResponse GET /tgrade/globalfee/v1beta1/minimum_gas_prices

Top

confio/poe/v1beta1/poe.proto

Params

Params defines the parameters for the PoE module.

Field Type Label Description
historical_entries uint32 HistoricalEntries is the number of historical entries to persist.
initial_val_engagement_points uint64 InitialValEngagementPoints defines the number of engagement for any new validator joining post genesis
min_delegation_amounts cosmos.base.v1beta1.Coin repeated MinDelegationAmount defines the minimum amount a post genesis validator needs to self delegate to receive any engagement points. One must be exceeded. No minimum condition set when empty.

PoEContractType

PoEContractType type of PoE contract

Name Number Description
UNDEFINED 0
STAKING 1
VALSET 2
ENGAGEMENT 3
MIXER 4
DISTRIBUTION 5
OVERSIGHT_COMMUNITY 6
OVERSIGHT_COMMUNITY_PROPOSALS 7
COMMUNITY_POOL 8
VALIDATOR_VOTING 9
ARBITER_POOL 10
ARBITER_POOL_VOTING 11

Top

confio/poe/v1beta1/genesis.proto

ArbiterPoolContractConfig

ArbiterPoolContractConfig initial setup config for the trusted circle

Field Type Label Description
name string Name of TRUSTED_CIRCLE
escrow_amount cosmos.base.v1beta1.Coin EscrowAmount The required escrow amount, in the default denom (utgd)
voting_rules VotingRules VotingRules rules for the tally
deny_list_contract_address string DenyListContractAddress is an optional cw4 contract with list of addresses denied to be part of TrustedCircle
dispute_cost cosmos.base.v1beta1.Coin DisputeCost The required dispute amount, in the default denom (utgd)
waiting_period google.protobuf.Duration

CommunityPoolContractConfig

CommunityPoolContractConfig initial setup config for the contract

Field Type Label Description
voting_rules VotingRules VotingRules rules for the tally

EngagementContractConfig

EngagementContractConfig initial setup config

Field Type Label Description
halflife google.protobuf.Duration

GenesisState

GenesisState - initial state of module

Field Type Label Description
params Params params defines all the parameter of the module
seed_contracts SeedContracts SeedContracts stores and instantiates the Proof of Engagement contracts on the chain.
import_dump ImportDump ImportDump restores the state from an exported state genesis

ImportDump

ImportDump has all module data for non seed mode.

Field Type Label Description
contracts PoEContract repeated Contracts PoE contract addresses and types

MixerContractConfig

Mixer contract setup. See https://github.com/confio/poe-contracts/tree/main/contracts/tg4-mixer

Field Type Label Description
sigmoid MixerContractConfig.Sigmoid Sigmoid returns a sigmoid-like value of staked amount times engagement points. See the Proof-of-Engagement white-paper for details.

MixerContractConfig.Sigmoid

Field Type Label Description
max_points uint64
p string
s string

OversightCommitteeContractConfig

OversightCommitteeContractConfig initial setup config for the trusted circle

Field Type Label Description
name string Name of TRUSTED_CIRCLE
escrow_amount cosmos.base.v1beta1.Coin EscrowAmount The required escrow amount, in the default denom (utgd)
voting_rules VotingRules VotingRules rules for the tally
deny_list_contract_address string DenyListContractAddress is an optional cw4 contract with list of addresses denied to be part of TrustedCircle

PoEContract

PoEContract address and type information

Field Type Label Description
contract_type PoEContractType ContractType type.
address string Address is the bech32 address string

SeedContracts

SeedContracts contains the contract configuration and group members to setup all PoE contracts on chain.

Field Type Label Description
gen_txs bytes repeated GenTxs defines the genesis transactions to create a validator.
bootstrap_account_address string BootstrapAccountAddress single address that is set as bootstrap-account for the PoE contracts in seed mode.
engagement TG4Member repeated Engagement weighted members of the engagement group. Validators should be in here.
stake_contract_config StakeContractConfig
valset_contract_config ValsetContractConfig
engagement_contract_config EngagementContractConfig
bond_denom string BondDenom defines the bondable coin denomination.
oversight_committee_contract_config OversightCommitteeContractConfig
community_pool_contract_config CommunityPoolContractConfig
validator_voting_contract_config ValidatorVotingContractConfig
oversight_community_members string repeated
arbiter_pool_members string repeated
arbiter_pool_contract_config ArbiterPoolContractConfig
mixer_contract_config MixerContractConfig

StakeContractConfig

StakeContractConfig initial setup config

Field Type Label Description
min_bond uint64
tokens_per_point uint64
unbonding_period google.protobuf.Duration
claim_autoreturn_limit uint32

TG4Member

TG4Member member of the Engagement group.

Field Type Label Description
address string Address is the bech32 address string
points uint64

ValidatorVotingContractConfig

ValidatorVotingContractConfig CommunityPoolContractConfig

Field Type Label Description
voting_rules VotingRules VotingRules rules for the tally

ValsetContractConfig

ValsetContractConfig initial setup config

Field Type Label Description
min_points uint64
max_validators uint32 MaxValidators The maximum number of validators that can be included in the Tendermint validator set.
epoch_length google.protobuf.Duration EpochLength We update the Tendermint validator set only once per epoch. Epoch # is env.block.time/epoch_length (round down). The first block with a new epoch number will trigger a new validator calculation.
epoch_reward cosmos.base.v1beta1.Coin
scaling uint32 Scaling is the factor to multiply cw4-group weights to produce the Tendermint validator power
fee_percentage string FeePercentage is the percentage of total accumulated fees that is subtracted from tokens minted as rewards. 50% by default. To disable this feature just set it to 0 (which effectively means that fees don't affect the per-epoch reward).
community_pool_reward_ratio string CommunityPoolRewardRation in percentage
engagement_reward_ratio string EngagementRewardRatio reward ration in percentage for all
validator_reward_ratio string ValidatorRewardRation in percentage for all
auto_unjail bool AutoUnjail if set to true, we will auto-unjail any validator after their jailtime is over.
double_sign_slash_ratio string DoubleSignSlashRatio Validators who are caught double signing are jailed forever and their bonded tokens are slashed based on this value.
verify_validators bool When a validator joins the valset, verify they sign the first block since joining or jail them for a period otherwise.

The verification happens every time the validator becomes an active validator, including when they are unjailed or when they just gain enough power to participate. | | offlineJailDuration | google.protobuf.Duration | | OfflineJailDuration duration to jail a validator for in case they don't sign their first epoch boundary block. After the period, they have to pass verification again, ad infinitum. |

VotingRules

VotingRules contains configuration for the tally.

Field Type Label Description
voting_period uint32 VotingPeriod Voting period in days
quorum string Quorum voting quorum percentage (1-100)
threshold string Threshold voting threshold percentage (50-100)
allow_end_early bool AllowEndEarly If true, and absolute threshold and quorum are met, we can end before voting period finished. (Recommended value: true, unless you have special needs)

Top

confio/poe/v1beta1/query.proto

QueryContractAddressRequest

QueryContractAddressRequest is the request type for the Query/ContractAddress RPC method.

Field Type Label Description
contract_type PoEContractType ContractType is the type of contract

QueryContractAddressResponse

QueryContractAddressRequest is the response type for the Query/ContractAddress RPC method.

Field Type Label Description
address string

QueryUnbondingPeriodRequest

QueryUnbondingPeriodRequest is request type for the Query/UnbondingPeriod RPC method

QueryUnbondingPeriodResponse

QueryUnbondingPeriodResponse is response type for the Query/UnbondingPeriod RPC method

Field Type Label Description
time google.protobuf.Duration Time is the time that must pass

QueryValidatorDelegationRequest

QueryValidatorDelegationRequest is request type for the Query/ValidatorDelegation RPC method

Field Type Label Description
validator_addr string validator_addr defines the validator address to query for.

QueryValidatorDelegationResponse

QueryValidatorDelegationResponse is response type for the Query/ValidatorDelegation RPC method

Field Type Label Description
balance cosmos.base.v1beta1.Coin

QueryValidatorEngagementRewardRequest

QueryValidatorEngagementRewardRequest is the request type for the Query/ValidatorEngagementReward RPC method.

Field Type Label Description
validator_address string validator_address defines the validator address to query for.

QueryValidatorEngagementRewardResponse

QueryValidatorEngagementRewardResponse is the response type for the Query/ValidatorEngagementReward RPC method.

Field Type Label Description
reward cosmos.base.v1beta1.DecCoin

QueryValidatorOutstandingRewardRequest

QueryValidatorOutstandingRewardRequest is the request type for the Query/ValidatorOutstandingReward RPC method.

Field Type Label Description
validator_address string validator_address defines the validator address to query for.

QueryValidatorOutstandingRewardResponse

QueryValidatorOutstandingRewardResponse is the response type for the Query/ValidatorOutstandingReward RPC method.

Field Type Label Description
reward cosmos.base.v1beta1.DecCoin

QueryValidatorUnbondingDelegationsRequest

QueryValidatorUnbondingDelegationsRequest is required type for the Query/ValidatorUnbondingDelegations RPC method

Field Type Label Description
validator_addr string validator_addr defines the validator address to query for.
pagination cosmos.base.query.v1beta1.PageRequest pagination defines an optional pagination for the request.

QueryValidatorUnbondingDelegationsResponse

QueryValidatorUnbondingDelegationsResponse is response type for the Query/ValidatorUnbondingDelegations RPC method.

Field Type Label Description
entries cosmos.staking.v1beta1.UnbondingDelegationEntry repeated unbonding delegation entries
pagination cosmos.base.query.v1beta1.PageResponse pagination defines the pagination in the response.

Query

Query defines the gRPC querier service.

Method Name Request Type Response Type Description HTTP Verb Endpoint
ContractAddress QueryContractAddressRequest QueryContractAddressResponse ContractAddress queries the address for one of the PoE contracts GET /tgrade/poe/v1beta1/contract/{contract_type}
Validators .cosmos.staking.v1beta1.QueryValidatorsRequest .cosmos.staking.v1beta1.QueryValidatorsResponse Validators queries all validators that match the given status. GET /tgrade/poe/v1beta1/validators
Validator .cosmos.staking.v1beta1.QueryValidatorRequest .cosmos.staking.v1beta1.QueryValidatorResponse Validator queries validator info for given validator address. GET /tgrade/poe/v1beta1/validators/{validator_addr}
UnbondingPeriod QueryUnbondingPeriodRequest QueryUnbondingPeriodResponse Validator queries validator info for given validator address. GET /tgrade/poe/v1beta1/unbonding
ValidatorDelegation QueryValidatorDelegationRequest QueryValidatorDelegationResponse ValidatorDelegation queries self delegated amount for given validator. GET /poe/tgrade/v1beta1/validators/{validator_addr}/delegation
ValidatorUnbondingDelegations QueryValidatorUnbondingDelegationsRequest QueryValidatorUnbondingDelegationsResponse ValidatorUnbondingDelegations queries unbonding delegations of a validator. GET /tgrade/poe/v1beta1/validators/{validator_addr}/unbonding_delegations
HistoricalInfo .cosmos.staking.v1beta1.QueryHistoricalInfoRequest .cosmos.staking.v1beta1.QueryHistoricalInfoResponse HistoricalInfo queries the historical info for given height. GET /tgrade/poe/v1beta1/historical_info/{height}
ValidatorOutstandingReward QueryValidatorOutstandingRewardRequest QueryValidatorOutstandingRewardResponse ValidatorOutstandingRewards queries rewards of a validator address. GET /tgrade/poe/v1beta1/validators/{validator_address}/outstanding_reward
ValidatorEngagementReward QueryValidatorEngagementRewardRequest QueryValidatorEngagementRewardResponse ValidatorEngagementReward queries rewards of a validator address. GET /tgrade/poe/v1beta1/validators/{validator_address}/engagement_reward

Top

confio/poe/v1beta1/tx.proto

MsgCreateValidator

MsgCreateValidator defines a PoE message for creating a new validator. Based on the SDK staking.MsgCreateValidator

Field Type Label Description
description cosmos.staking.v1beta1.Description Description meta data
operator_address string OperatorAddress is the bech32 address string
pubkey google.protobuf.Any Pubkey public key
amount cosmos.base.v1beta1.Coin Amount defines the initial staking amount from a liquid balance
vesting_amount cosmos.base.v1beta1.Coin VestingAmount defines the initial staking amount from a vesting account balance

MsgCreateValidatorResponse

MsgCreateValidatorResponse defines the MsgCreateValidator response type.

MsgDelegate

MsgDelegate defines a SDK message for performing a self delegation of coins by a node operator

Field Type Label Description
operator_address string
amount cosmos.base.v1beta1.Coin
vesting_amount cosmos.base.v1beta1.Coin

MsgDelegateResponse

MsgDelegateResponse defines the Msg/Delegate response type.

MsgUndelegate

MsgUndelegate defines a SDK message for performing an undelegation from a node operator

Field Type Label Description
operator_address string
amount cosmos.base.v1beta1.Coin

MsgUndelegateResponse

MsgUndelegateResponse defines the Msg/Undelegate response type.

Field Type Label Description
completion_time google.protobuf.Timestamp

MsgUpdateValidator

MsgCreateValidator defines a PoE message for updating validator metadata

Field Type Label Description
description cosmos.staking.v1beta1.Description New Description meta data
operator_address string OperatorAddress is the bech32 address string Also know as "signer" in other messages

MsgUpdateValidatorResponse

MsgUpdateValidatorResponse defines the MsgUpdateValidator response type.

Msg

Msg defines the staking Msg service.

Method Name Request Type Response Type Description HTTP Verb Endpoint
CreateValidator MsgCreateValidator MsgCreateValidatorResponse CreateValidator defines a method for creating a new validator.
UpdateValidator MsgUpdateValidator MsgUpdateValidatorResponse MsgCreateValidator defines a method for updating validator metadata
Delegate MsgDelegate MsgDelegateResponse Delegate defines a method for performing a self delegation of coins by a node operator
Undelegate MsgUndelegate MsgUndelegateResponse Undelegate defines a method for performing an undelegation from a node operator

Top

confio/twasm/v1beta1/contract_extension.proto

RegisteredPrivilege

RegisteredPrivilege stores position and privilege name

Field Type Label Description
position uint32
privilege_type string

TgradeContractDetails

TgradeContractDetails is a custom extension to the wasmd ContractInfo

Field Type Label Description
registered_privileges RegisteredPrivilege repeated

Top

confio/twasm/v1beta1/genesis.proto

Contract

Contract struct encompasses ContractAddress, ContractInfo, and ContractState

Field Type Label Description
contract_address string
contract_info cosmwasm.wasm.v1.ContractInfo
kv_model KVModel
custom_model CustomModel

CustomModel

CustomModel contains the raw json data for a contract to seed its state on import

Field Type Label Description
msg bytes Msg json encoded message to be passed to the contract on import

GenesisState

Field Type Label Description
params cosmwasm.wasm.v1.Params Params sdk type Params for wasmd
codes cosmwasm.wasm.v1.Code repeated Codes has all stored wasm codes and metadata
contracts Contract repeated Contracts contains all instantiated contracts, state and metadata
sequences cosmwasm.wasm.v1.Sequence repeated Sequences names and values
gen_msgs cosmwasm.wasm.v1.GenesisState.GenMsgs repeated GenMsgs has wasmd sdk type messages to execute in the genesis phase
privileged_contract_addresses string repeated PrivilegedContractAddresses is a list of contract addresses that can have special permissions
pinned_code_ids uint64 repeated PinnedCodeIDs has codeInfo ids for wasm codes that are pinned in cache

KVModel

KVModel is a wrapper around the wasmd default key value model.

Field Type Label Description
models cosmwasm.wasm.v1.Model repeated

Top

confio/twasm/v1beta1/proposal.proto

DemotePrivilegedContractProposal

PromoteToPrivilegedContractProposal gov proposal content type to remove "privileges" from a contract

Field Type Label Description
title string Title is a short summary
description string Description is a human readable text
contract string Contract is the address of the smart contract

PromoteToPrivilegedContractProposal

PromoteToPrivilegedContractProposal gov proposal content type to add "privileges" to a contract

Field Type Label Description
title string Title is a short summary
description string Description is a human readable text
contract string Contract is the address of the smart contract

Top

confio/twasm/v1beta1/query.proto

QueryContractsByPrivilegeTypeRequest

QueryContractsByPrivilegeTypeRequest is the request type for the Query/ContractsByPrivilegeType RPC method

Field Type Label Description
privilege_type string

QueryContractsByPrivilegeTypeResponse

QueryContractsByPrivilegeTypeResponse is the response type for the Query/ContractsByPrivilegeType RPC method

Field Type Label Description
contracts string repeated contracts are a set of contract addresses

QueryPrivilegedContractsRequest

QueryPrivilegedContractsResponse is the request type for the Query/PrivilegedContracts RPC method

QueryPrivilegedContractsResponse

QueryPrivilegedContractsResponse is the response type for the Query/PrivilegedContracts RPC method

Field Type Label Description
contracts string repeated contracts are a set of contract addresses

Query

Query provides defines the gRPC querier service

Method Name Request Type Response Type Description HTTP Verb Endpoint
PrivilegedContracts QueryPrivilegedContractsRequest QueryPrivilegedContractsResponse PrivilegedContracts returns all privileged contracts GET /tgrade/twasm/v1beta1/contracts/privileged
ContractsByPrivilegeType QueryContractsByPrivilegeTypeRequest QueryContractsByPrivilegeTypeResponse ContractsByPrivilegeType returns all contracts that have registered for the privilege type GET /tgrade/twasm/v1beta1/contracts/privilege/{privilege_type}

Scalar Value Types

.proto Type Notes C++ Java Python Go C# PHP Ruby
double double double float float64 double float Float
float float float float float32 float float Float
int32 Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead. int32 int int int32 int integer Bignum or Fixnum (as required)
int64 Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead. int64 long int/long int64 long integer/string Bignum
uint32 Uses variable-length encoding. uint32 int int/long uint32 uint integer Bignum or Fixnum (as required)
uint64 Uses variable-length encoding. uint64 long int/long uint64 ulong integer/string Bignum or Fixnum (as required)
sint32 Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s. int32 int int int32 int integer Bignum or Fixnum (as required)
sint64 Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s. int64 long int/long int64 long integer/string Bignum
fixed32 Always four bytes. More efficient than uint32 if values are often greater than 2^28. uint32 int int uint32 uint integer Bignum or Fixnum (as required)
fixed64 Always eight bytes. More efficient than uint64 if values are often greater than 2^56. uint64 long int/long uint64 ulong integer/string Bignum
sfixed32 Always four bytes. int32 int int int32 int integer Bignum or Fixnum (as required)
sfixed64 Always eight bytes. int64 long int/long int64 long integer/string Bignum
bool bool boolean boolean bool bool boolean TrueClass/FalseClass
string A string must always contain UTF-8 encoded or 7-bit ASCII text. string String str/unicode string string string String (UTF-8)
bytes May contain any arbitrary sequence of bytes. string ByteString str []byte ByteString string String (ASCII-8BIT)

Tgrade CLI Reference

Generate a new key (address) and add to your keyring

tgrade keys add my-key

Add key from a seed phrase to your keyring

tgrade keys add my-other-key --recover

Show an address for a key

tgrade keys show -a my-key

Query an account balance

tgrade q bank balances tgrade1mdcqr6r3fwxkxwvu5zee7hgpqmhr4a4jm59m3d --node=https://rpc.internal-12.tgrade.confio.run:443

Transfer some tokens

tgrade tx bank send my-other-key tgrade1mdcqr6r3fwxkxwvu5zee7hgpqmhr4a4jm59m3d 10tgd -b block --chain-id=tgrade-internal-12 --node=https://rpc.internal-12.tgrade.confio.run:443 --fees=10000utgd

Community (Discord)

Join the Tgrade discord to ask questions or to meet others also building on Tgrade to discuss strategies, best practices etc...

Clone this wiki locally