Skip to content

Commit

Permalink
Merge branch 'main' into barriebyron-patch-cli-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dongsam committed Jan 12, 2022
2 parents 8ccb4c8 + 3b7654f commit 4c0f13b
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 66 deletions.
20 changes: 12 additions & 8 deletions docs/How-To/api/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
---
Title: REST APIs
Description: A high-level overview of gRPC-gateway REST Routes in budget module.
Title: REST APIs for Budget Module
Description: A high-level overview of gRPC-gateway REST routes for the budget module.
---

# REST APIs for Budget Module

A high-level overview of gRPC-gateway REST routes for the budget module.

## Swagger Documentation

- [Swagger Docs v1.0.0](https://app.swaggerhub.com/apis-docs/gravity-devs/budget/1.0.0)

## gRPC-gateway REST Routes

In order to test out the following REST routes, you need to set up a local node to query from. You can refer to this [localnet tutorial](../../Tutorials/localnet) on how to build `budgetd` binary and bootstrap a local network in your local machine.
To test out the budget module API REST routes, you must first set up a local node to query from. See the [Localnet tutorial](../../Tutorials/localnet) for steps to build the `budgetd` binary and bootstrap a local network on your local machine.

- [Params](#Params)
- [Budgets](#Budgets)
- [Addresses](#Addresses)

### Params

Query the values set as budget parameters
Query the values set as budget parameters:

http://localhost:1317/cosmos/budget/v1beta1/params <!-- markdown-link-check-disable-line -->

Expand All @@ -41,7 +45,7 @@ http://localhost:1317/cosmos/budget/v1beta1/params <!-- markdown-link-check-disa

### Budgets

Query all the budget plans exist in the network
Query all the budget plans exist in the network:

http://localhost:1317/cosmos/budget/v1beta1/budgets <!-- markdown-link-check-disable-line -->

Expand Down Expand Up @@ -71,7 +75,7 @@ http://localhost:1317/cosmos/budget/v1beta1/budgets <!-- markdown-link-check-dis

### Addresses

Query the address of `fee_collector` with address type 1(`AddressType20Bytes`)
Query the address of `fee_collector` with address type 1(`AddressType20Bytes`):

http://localhost:1317/cosmos/budget/v1beta1/addresses/fee_collector?type=1 <!-- markdown-link-check-disable-line -->

Expand All @@ -81,12 +85,12 @@ http://localhost:1317/cosmos/budget/v1beta1/addresses/fee_collector?type=1 <!--
}
```

Query the address of `GravityDEXFarmingBudget` on farming module with default address type 0(`AddressType32Bytes`)
Query the address of `GravityDEXFarmingBudget` on farming module with default address type 0(`AddressType32Bytes`):

http://localhost:1317/cosmos/budget/v1beta1/addresses/GravityDEXFarmingBudget?module_name=farming <!-- markdown-link-check-disable-line -->

```json
{
"address": "cosmos1228ryjucdpdv3t87rxle0ew76a56ulvnfst0hq0sscd3nafgjpqqkcxcky"
}
```
```
20 changes: 4 additions & 16 deletions docs/Tutorials/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
# Tutorials Documentation
# Tutorials

How to use the budget module Tutorials documentation.
Tutorials come in various forms:

- [Tutorials Documentation](#tutorials-documentation)
- [Introduction](#introduction)
- [Layout](#layout)

## Introduction

This section contains Tutorials documentation for budget module.

## Layout

Tutorials Documentation will come in various forms:

* [Demo](./demo) - contains any type of demo or presentation for budget module
* [Localnet](./localnet) - contains guideline of how to build `budgetd` and bootstrap local network
* [Demo](./demo) - Any type of demo or presentation for budget module
* [Localnet](./localnet) - Guidelines to build `budgetd` and bootstrap local network
12 changes: 8 additions & 4 deletions docs/Tutorials/localnet/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
---
Title: Localnet
Description: A tutorial of how to build `budgetd` and bootstrap local network.
Description: How to build the `budgetd` binary and bootstrap a local network.
---

### Get Budget Module source code
# Localnet

This tutorial provides steps to build the `budgetd` binary and bootstrap a local network.

# Get Budget Module Source Code

```bash
git clone https://github.com/tendermint/budget.git
cd budget
make install
```

### Boostrap
### Bootstrap a Chain

The following script is prepared to bootstrap a single chain with a single validator in your local machine. Copy the script and run them in your terminal.
The following script bootstraps a single chain in your local machine with a single validator. Copy the script and run it in your terminal.

```bash
# Configure variables
Expand Down
52 changes: 32 additions & 20 deletions x/budget/spec/01_concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,73 @@

## Budget Module

`x/budget` is a simple Cosmos SDK module that implements budget functionality. It is an independent module from other SDK modules and core functionality is to enable anyone to create a budget plan through parameter change governance proposal. Once it is agreed within the community, voted, and passed, it uses `SourceAddress` to distribute amount of coins relative to the rate defined in the plan to the `DestinationAddress`. At each `BeginBlock`, collecting all budgets and distribution take place every `EpochBlocks`. `EpochBlocks` is a global parameter that can be modified by a governance proposal.
`x/budget` is a simple Cosmos SDK module that implements budget functionality.

A primary use case is for Gravity DEX farming plan. A budget module can be used to create a budget plan that has `SourceAddress` for Cosmos Hub's [FeeCollector](https://github.com/cosmos/cosmos-sdk/blob/v0.44.0/x/auth/types/keys.go#L15) module account which collects transaction gas fees and part of ATOM inflation. Then, `SourceAddress` plans to distribute some amount of coins to `DestinationAddress` for farming plan.
After the module is agreed within the community, voted, and passed, the core functionality of this independent module enables anyone to create a budget plan through parameter change governance proposal.

High level overview:

- The budget module uses `SourceAddress` to distribute to the `DestinationAddress`.
- The amount of coins is relative to the rate defined in the plan.
- The module collects all budgets at each `BeginBlock`.
- Distribution takes place at every `EpochBlocks`, a global parameter that can be modified by a governance proposal.

A primary use case for the budget module is for the Gravity DEX farming plan.

Use the budget module to create a budget plan that has `SourceAddress` for the Cosmos Hub [FeeCollector](https://github.com/cosmos/cosmos-sdk/blob/v0.44.0/x/auth/types/keys.go#L15) module account that collects transaction gas fees and part of ATOM inflation. Then, `SourceAddress` plans to distribute some amount of coins to `DestinationAddress` for farming plan.

### Budget Plan for ATOM Inflation Use Case

Cosmos SDK's current reward workflow
The Cosmos SDK current reward workflow:

- In AnteHandler
- In AnteHandler:

- Gas fees are collected in ante handler and they are sent to `FeeCollectorName` module account
- Gas fees are collected in ante handler and are sent to the `FeeCollectorName` module account

- Reference the following lines of code
- Reference the following lines of code:

+++ https://github.com/cosmos/cosmos-sdk/blob/v0.44.0/x/auth/ante/fee.go#L112-L140

- In `x/mint` module
- In `x/mint` module:

- ATOM inflation is minted in `x/mint` module and they are sent to `FeeCollectorName` module account
- ATOM inflation is minted in `x/mint` module and is sent to the `FeeCollectorName` module account

- Reference the following lines of code
- Reference the following lines of code:

+++ https://github.com/cosmos/cosmos-sdk/blob/v0.44.0/x/mint/abci.go#L27-L40

+++ https://github.com/cosmos/cosmos-sdk/blob/v0.44.0/x/mint/keeper/keeper.go#L108-L110

- In `x/distribution` module
- In `x/distribution` module:

- Send all rewards in `FeeCollectorName` to distribution module account

- From `distributionModuleAccount`, substitute `communityTax`

- Rest are distributed to proposer and validator reward pools
- Remaining rewards are distributed to proposer and validator reward pools

- Substituted amount for community budget is saved in kv store
- Substituted amount for community budget is saved in key-value store

- Reference the following lines of code
- Reference the following lines of code:

+++ https://github.com/cosmos/cosmos-sdk/blob/v0.44.0/x/distribution/keeper/allocation.go#L13-L102

Implementation with Budget Module
Implementation with `x/budget` module:

- A budget module is 100% independent of other Cosmos SDK's existing modules
- A budget module is 100% independent of all other Cosmos SDK modules

- BeginBlock processing order is the following order
- BeginBlock processing order is:

- mint module → budget module → distribution module

- Distribute ATOM inflation and transaction gas fees to different budget purposes
- Distribute ATOM inflation and transaction gas fees to different budget purposes:

- ATOM inflation and gas fees are accumulated in `FeeCollectorName` module account

- Distribute budget amounts from `FeeCollectorName` module account to each budget pool module account

- Rest amounts stay in `FeeCollectorName` so that distribution module can use it for community fund and staking rewards distribution as what it is doing now
- Remaining amounts stay in `FeeCollectorName` so that distribution module can use them for community fund and staking rewards distribution (no change to current `FeeCollectorName` implementation)

- Create, modify or remove budget plans via governance process
- A budget plan can be created, modified or removed by parameter change governance proposal
- Create, modify or remove budget plans by using governance process:

- A budget plan can be created, modified, or removed by parameter change governance proposal
3 changes: 2 additions & 1 deletion x/budget/spec/02_state.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<!-- order: 2 -->
# State

## Budget

Budget object is not stored in KVStore.
The budget object is not stored in key-value store (KVStore).

```go
// Budget contains budget information
Expand Down
10 changes: 7 additions & 3 deletions x/budget/spec/03_state_transitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

# State Transitions

This document describes the state transaction operations pertaining to the budget module.
The state transaction operations for the budget module are:

- CollectBudgets

- TotalCollectedCoins

## CollectBudgets

Get all budgets registered in `params.Budgets` and select the valid budgets to collect budgets for the block by its respective plan.
This state transition occurs at each `BeginBlock`. You can read more about it in [04_begin_block.md](04_begin_block.md).

This state transition occurs at each `BeginBlock`. See [Begin-Block](04_begin_block.md).

## TotalCollectedCoins

`TotalCollectedCoins` are accumulated coins in a budget since the creation of the budget.
This state transition occurs at each `BeginBlock` with `CollectBudgets`. You can read more about it in [04_begin_block.md](04_begin_block.md).

This state transition occurs at each `BeginBlock` at the same time as the `CollectBudgets` operation. See [Begin-Block](04_begin_block.md).
6 changes: 3 additions & 3 deletions x/budget/spec/04_begin_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

# Begin-Block

At each `BeginBlock`, get all budgets registered in `params.Budgets` and select the valid budgets to collect budgets for the block by its respective plan (defined rate, source address, destination address, start time and end time). Then, it distributes the collected amount of coins from `SourceAddrss` to `DestinationAddress`.
At the beginning of each block, the `BeginBlock`, the budget module gets all budgets that are registered in `params.Budgets`, then selects the valid budgets to collect budgets for the block by its respective plan (defined rate, source address, destination address, start time, and end time). Then, distributes the collected amount of coins from `SourceAddress` to `DestinationAddress`.

+++ https://github.com/tendermint/budget/blob/main/x/budget/abci.go#L15-L22

## Workflow

1. Get all the budgets registered in `params.Budgets` and proceed with the valid and not expired budgets. Otherwise, it exits and waits for the next block.
1. Get all the budgets registered in `params.Budgets` and proceed with the valid and unexpired budgets. Otherwise, exit and wait for the next block.

2. Create a map by `SourceAddress` to handle the budgets for the same `SourceAddress` together based on the same balance when calculating rates for the same `SourceAddress`.
2. Create a map by `SourceAddress` to handle the budgets for the same `SourceAddress` based on the same balance when calculating rates for the same `SourceAddress`.

3. Collect budgets from `SourceAddress` and send amount of coins to `DestinationAddress` relative to the rate of each budget`.

Expand Down
4 changes: 3 additions & 1 deletion x/budget/spec/05_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

# Events

The budget module emits the following events.

## BeginBlocker

### Budget Collection Result for each Budget on this block
### Budget Collection Result for Each Budget on This Block

| Type | Attribute Key | Attribute Value |
| ---------------- | ------------------- | -------------------- |
Expand Down
32 changes: 23 additions & 9 deletions x/budget/spec/06_params.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,48 @@ The budget module contains the following parameters:
## EpochBlocks

The universal epoch length in number of blocks.
Every process for budget collecting is executed with this `epoch_blocks` frequency.

The default value is 1 and all budget collections are disabled if the value is 0. Budget collection logic is executed with the following condition.
Every process for budget collecting is executed with the `epoch_blocks` frequency.

- The default value is 1.
- All budget collections are disabled if the value is 0.

Budget collection logic is executed with the following condition.

```
params.EpochBlocks > 0 && Current Block Height % params.EpochBlocks == 0
```

You can reference [the line of the code](https://github.com/tendermint/budget/blob/main/x/budget/keeper/budget.go#L78).
Reference the following code:
+++ https://github.com/tendermint/budget/blob/main/x/budget/keeper/budget.go#L78

## Budgets

The Budget structure can be found in [02_state.md](02_state.md).
The budget structure is described in [State](02_state.md).

Parameter of a budget can be added, modified, and deleted through [parameter change governance proposal](https://docs.cosmos.network/master/modules/gov/01_concepts.html#proposal-submission).

An example of how to add a budget plan can be found in this [docs/How-To/cli](../../../docs/How-To/cli) guide.
For an example of how to add a budget plan, see [Propose a Budget Plan](../../../docs/How-To/cli#propose-a-budget-plan) in the budgetd CLI guide.

### Validity Checks

- Budget name only allows letters(`A-Z, a-z`), digits(`0-9`), and `-` without spaces. Also, it has the maximum length of 50 and it should not be duplicate with the existing budget names.
- Budget name:

- Supports valid characters are letters (`A-Z, a-z`), digits(`0-9`), and `-`.

- Must not include spaces.

- Has a maximum length of 50.

- Must be unique among existing budget names.

- Validate `DestinationAddress` address.

- Validate `SourceAddress` address.

- EndTime should not be earlier than StartTime.
- EndTime must not be earlier than StartTime.

- The total rate of budgets with the same `SourceAddress` value should not exceed 1 (100%).
- The total rate of budgets with the same `SourceAddress` value must not exceed 1 (100%).

+++ https://github.com/tendermint/budget/blob/main/x/budget/types/budget.go#L33-L63
Reference the following code:
+++ https://github.com/tendermint/budget/blob/main/x/budget/types/budget.go#L33-L63
2 changes: 1 addition & 1 deletion x/budget/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Abstract

This document specifies the budget module of the Cosmos SDK that serves budget feature
This document specifies the budget module of the Cosmos SDK. This independent Cosmos SDK module implements budget functionality to create a budget plan through parameter change governance proposal.

## Contents

Expand Down

0 comments on commit 4c0f13b

Please sign in to comment.