algogovernance

command module
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 1 Imported by: 0

README

algogovernance

Go Reference

A Golang API wrapper for Algorand's Governance API and CLI tool.

Installation

Add the Go package:

$ go get github.com/Dan6erbond/algogovernance

Install the CLI tool:

$ go install github.com/Dan6erbond/algogovernance

Quick Start

Algorand's Governance API is a RESTful API that doesn't require keys or tokens to access, which is why all its methods are available under the pkg/client module.

Fetching the current period and its governors:

package main

import (
	"github.com/Dan6erbond/algogovernance/pkg/client"
)

func main() {
	activePeriod, _ := client.GetActivePeriod()
  governors, _ := client.GetPeriodGovernors(activePeriod.Slug, "", "", "", "cursor", "", "", "")
  for governors.HasNext() {
    governors, _ = governors.GetNext()
  }
}

algogovernance also comes with helpers to estimate rewards for a given governor and governance period. Those are found in the pkg/rewards module.

Getting the estimated rewards for the current period:

package main

import (
	algoRewards "github.com/Dan6erbond/algogovernance/pkg/rewards"
)

func main() {
  address := "3RYOY2LTPC6GLT3ZYE4LUFGGAEMY7GRENZQO7RFNGK2LGCV77QNASK6C6Y"
  rewards, _ := algoRewards.GetRewardsForCurrentPeriod(address)
}

CLI Tool

The CLI tool is built with Cobra and uses Viper configuration for governor wallet addresses. It supports the following commands:

  • cfg: View the current configuration.
  • currentPeriod: Get an overview of the current period and expected governance rewards.
  • rewards: Get the expected rewards for a given period, defaults to the current active period.

Documentation

The documentation is available at pkg.go.dev: algogovernance command - github.com/Dan6erbond/algogovernance - pkg.go.dev

License

This package is licensed under the MIT license.

Documentation

Overview

Package main and its subdirectories contain the Algogovernance API client wrapper and the command line interface.

Algogovernance is a full API wrapper for the Algorand Governance Platform enabling developers to get periods, total staked ALGO, voting topics and options, as well as total votes and other data relevant to Algorand governance.

Additionally the repository includes a CLI allowing users to query commonly used data such as information about the current period, and calculate rewards for a given governor.

Using The CLI

The CLI can be installed from Git, and then ran with the algogovernance command:

$ go install github.com/Dan6erbond/algogovernance
$ algogovernance currentPeriod

Certain configuration parameters, such as governor can be specified in a .algogovernance.yml file in order to avoid having to pass them as arguments to the CLI.

Save the file to $HOME/.algogovernance.yml and then run the CLI to check that the config is loaded:

$ algogovernance cfg
Governor: 3RYOY2LTPC6GLT3ZYE4LUFGGAEMY7GRENZQO7RFNGK2LGCV77QNASK6C6Y

Making Requests

All the client code is made available in the pkg/client folder to to make requests to the Algorand Governance API and supports features such as pagination, sorting and downloads.

Since the Algorand Governance API is unpermissioned, no API keys are required to make requests. Simply call methods from the client package after importing it like so:

import (
	"github.com/Dan6erbond/algogovernance/pkg/client"
)

func main() {
	activePeriod, _ := client.GetActivePeriod()
	governors, _ := client.GetPeriodGovernors(activePeriod.Slug, "", "", "", "cursor", "", "", "")
	for governors.HasNext() {
		governors, _ = governors.GetNext()
	}
}

Helpers

The package also comes with helpers in the pkg/helpers folder to perform common tasks, such as calculating rewards for a given period:

import (
	algoRewards "github.com/Dan6erbond/algogovernance/pkg/rewards"
)

func main() {
	address := "3RYOY2LTPC6GLT3ZYE4LUFGGAEMY7GRENZQO7RFNGK2LGCV77QNASK6C6Y"
	rewards, _ := algoRewards.GetRewardsForCurrentPeriod(address)
}

Directories

Path Synopsis
pkg
client
Package client contains data models and wrapper methods for the Algorand Governance API.
Package client contains data models and wrapper methods for the Algorand Governance API.
constants
Package constants provides values that can be used to simplify calculations and comparisons.
Package constants provides values that can be used to simplify calculations and comparisons.
rewards
Package rewards provides utilities for calculating rewards in Algorand's Governance.
Package rewards provides utilities for calculating rewards in Algorand's Governance.
utils
Package utils provides utilities for the Algorand Go Governance API.
Package utils provides utilities for the Algorand Go Governance API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL