Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown Linting Github Action #250

Closed
wants to merge 13 commits into from
11 changes: 11 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ jobs:
use-quiet-mode: 'yes'
use-verbose-mode: 'yes'
config-file: '.md-link-check.json'

markdown-linting:
name: "Markdown linting"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Check out the code
- name: Lint Code Base
uses: docker://avtodev/markdown-lint:v1
with:
args: "**/*.md"

unit_tests:
name: Unit Tests
Expand Down
19 changes: 19 additions & 0 deletions .markdownlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"MD024": false,
"MD013": false,
"MD033": false,
"MD041": false,
"MD001": false,
"MD036": false
}

/*
MD024: Multiple headings with the same content.
MD013: Lines are longer than the configured line_length (default: 80 characters)
MD033: Inline HTML
MD041: First line in a file should be a top-level heading
MD001: Heading levels should only increment by one level at a time
MD036: Emphasis used instead of a heading

Markdown lint rules: https://github.com/DavidAnson/markdownlint/blob/v0.25.1/doc/Rules.md
*/
8 changes: 2 additions & 6 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[comment]: <> ( <a href="">)
[comment]: <> ( <img alt="Codecov" src="https://img.shields.io/codecov/c/github/fetchai/cosmpy">)
[comment]: <> ( </a>)

<a href="https://img.shields.io/badge/lint-flake8-blueviolet">
<img alt="flake8" src="https://img.shields.io/badge/lint-flake8-yellow" >
Expand Down Expand Up @@ -56,16 +53,15 @@ This library uses python types which are generated (using [Google's Protocol Buf
When updating the Cosmos-SDK version that is supported by this library (see the version currently used under `COSMOS_SDK_VERSION` in [Makefile](Makefile)), you will need to fetch its corresponding protobuf schemas and generate their associated python types, replacing the existing ones.

> Note: This process has to be done only once when the Cosmos-SDK version supported by this library is changed.

> Note: To generate python types from Cosmos-SDK protobuf schemas, you will need [Google Protocol Buffers](https://developers.google.com/protocol-buffers/) compiler. A guide on how to install it can be found [here](https://fetchai.github.io/oef-sdk-python/user/install.html#protobuf-compiler).
To generate python types from Cosmos-SDK protobuf schemas, you will need [Google Protocol Buffers](https://developers.google.com/protocol-buffers/) compiler. A guide on how to install it can be found [here](https://fetchai.github.io/oef-sdk-python/user/install.html#protobuf-compiler).

- To regenerate the protobuf schema files, run the following:

```bash
make proto
```

>Note: For this library to be functional, only the python types generated from protobuf schemas are required, not the schema files themselves.
> Note: For this library to be functional, only the python types generated from protobuf schemas are required, not the schema files themselves.
> The schema files are fetched on-demand only to enable the generation of python types.
> Therefore, the schema files are intentionally stored as **local** files and are **NOT** checked in to this repository to minimise its filesystem footprint.

Expand Down
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* add address prefix to wallet
* Add fallback hashlib for Ubuntu 22.04 LTS

* fix: send funds in contract methods
* fix: send funds in contract methods
* fix integration tests
* fix: improve support for other chains

Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include *.yml
include *.json
include .firebaserc
include mkdocs.yml
include .markdownlintrc
recursive-include contracts *.wasm
recursive-include contracts *.txt
recursive-include docs *
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ It's better to discuss privately and try to find a solution first, to limit the

Thanks for your help!

The Fetch.ai community thank you for that. 🙇
The Fetch.ai community thank you for that. 🙇
1 change: 0 additions & 1 deletion docs/api/aerial/client/__init__.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,4 +564,3 @@ Broadcast transaction
**Returns**:

Submitted transaction

1 change: 0 additions & 1 deletion docs/api/aerial/client/bank.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ Create bank send message
**Returns**:

bank send message

1 change: 0 additions & 1 deletion docs/api/aerial/client/distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ Create withdraw delegator reward
**Returns**:

withdraw delegator reward message

1 change: 0 additions & 1 deletion docs/api/aerial/client/staking.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,3 @@ Create undelegate message
**Returns**:

Undelegate message

1 change: 0 additions & 1 deletion docs/api/aerial/client/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ Return timedelta for interval.
**Returns**:

timedelta

1 change: 0 additions & 1 deletion docs/api/aerial/coins.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ Parse the coins
**Returns**:

coins

1 change: 0 additions & 1 deletion docs/api/aerial/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,3 @@ Get the latest stable testnet
**Returns**:

latest stable testnet

1 change: 0 additions & 1 deletion docs/api/aerial/contract/__init__.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,3 @@ Get the contract details in json
**Returns**:

contract details in json

1 change: 0 additions & 1 deletion docs/api/aerial/contract/cosmwasm.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,3 @@ Create cosmwasm execute message
**Returns**:

cosmwasm execute message

1 change: 0 additions & 1 deletion docs/api/aerial/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,3 @@ _summary_

- `tx_hash`: transaction hash
- `minimum_required_fee`: Minimum required fee

1 change: 0 additions & 1 deletion docs/api/aerial/faucet.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ Get wealth from the faucet for the provided address.
**Raises**:

- `None`: RuntimeError of explicit faucet failures

1 change: 0 additions & 1 deletion docs/api/aerial/gas.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,3 @@ Get the block gas limit
**Returns**:

block gas limit

1 change: 0 additions & 1 deletion docs/api/aerial/tx.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,3 @@ Update transaction state to Final
**Returns**:

transaction with updated state

1 change: 0 additions & 1 deletion docs/api/aerial/tx_helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,3 @@ Wait to complete the transaction
**Returns**:

Submitted Transaction

1 change: 0 additions & 1 deletion docs/api/aerial/urls.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,3 @@ _summary_
**Returns**:

Parsed URL

1 change: 0 additions & 1 deletion docs/api/aerial/wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,3 @@ Get the signer of the wallet.
**Returns**:

signer

4 changes: 2 additions & 2 deletions docs/auto-compounder.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ It is important to note that each time an account performs a claim or a delegate
time_limit = 600
period = 100
```
Finally, we start a timer that claims rewards and delegates them in each time period. Notice that in the code below we constructed a while loop that will be running until the timer exceeds the `time limit`. Each loop will last the time specified in `period`. We query the balance before and after claiming rewards to get the value of the reward after any fees. If the true reward value is positive, we delegate those tokens to the validator, if it is negative, it means that the fees from claiming and delegating transactions exceeded the rewards, and therefore we won't delegate.

Finally, we start a timer that claims rewards and delegates them in each time period. Notice that in the code below we constructed a while loop that will be running until the timer exceeds the `time limit`. Each loop will last the time specified in `period`. We query the balance before and after claiming rewards to get the value of the reward after any fees. If the true reward value is positive, we delegate those tokens to the validator, if it is negative, it means that the fees from claiming and delegating transactions exceeded the rewards and therefore we won't delegate.

```python
time_check = 0
Expand Down Expand Up @@ -71,4 +71,4 @@ while time_check < time_limit:
time_check = time.monotonic() - start_time
```

You can view the full python example at [staking auto-compounder](https://github.com/fetchai/cosmpy/blob/develop/examples/aerial_compounder.py)
You can view the full python example at [staking auto-compounder](https://github.com/fetchai/cosmpy/blob/develop/examples/aerial_compounder.py)
1 change: 0 additions & 1 deletion docs/connect-to-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ ledger_client = LedgerClient(cfg)
```

A full list of chain identifiers, denominations and end-points can be found at the Cosmos [chain registry](https://github.com/cosmos/chain-registry/).

2 changes: 1 addition & 1 deletion docs/deploy-a-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You can now start interacting with the contract. To get the address of where the
print(f"Contract deployed at: {contract.address}")
```

You can query the values of the contract's state variables:
You can query the values of the contract's state variables:

```python
result = contract.query({"get": {"owner": wallet}})
Expand Down
9 changes: 4 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Cosmpy is a Python library for interacting with Cosmos-based blockchains.

* A simplified command line tool for querying and sending transactions to Cosmos-SDK blockchains.
* A simplified command line tool for querying and sending transactions to Cosmos-SDK blockchains.
* Features an easy interface for deploying and interacting with Cosmwasm smart contracts.
* Provides access to lower-level ledger APIs for advanced use-cases.
* Provides access to lower-level ledger APIs for advanced use-cases.

## To install

Expand All @@ -16,7 +16,7 @@ pip3 install cosmpy

## Repository

```
```text
https://github.com/fetchai/cosmpy
```

Expand All @@ -36,9 +36,8 @@ make new_env_dev

This creates a new `pipenv` virtual environment and installs the development dependencies.

Enter the virtual environment:
Enter the virtual environment:

``` bash
pipenv shell
```

8 changes: 6 additions & 2 deletions docs/liquidity-pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from cosmpy.aerial.contract import LedgerContract
from cosmpy.aerial.faucet import FaucetApi
from cosmpy.aerial.wallet import LocalWallet
```

Set the network configuration, define a local wallet and add some tokens to it using the FaucetApi

```python
Expand All @@ -23,6 +24,7 @@ wallet = LocalWallet.generate()
faucet_api = FaucetApi(NetworkConfig.latest_stable_testnet())
faucet_api.get_wealth(wallet.address())
```

Define the CW20, pair, and liquidity token contracts with the following addresses:

```python
Expand Down Expand Up @@ -89,7 +91,8 @@ tx = token_contract.execute({

tx.wait_to_complete()
```
## Add and Remove Liquidity

## Add and Remove Liquidity

You need to increase your wallet's allowance to provide CW20 tokens to the liquidity pool. You don't need to increase the allowance to provide atestfet

Expand All @@ -111,6 +114,7 @@ tx = token_contract.execute(

tx.wait_to_complete()
```

To set the amount of atestfet to be added to the liquidity pool and not influence the existing token prices, we need to choose an amount that matches the atestfet:CW20 token ratio already existing in the pool. For this reason, we will query the `pair_contract` pool to observe the atestfet:CW20 token ratio

```python
Expand Down Expand Up @@ -183,4 +187,4 @@ You can now query you LP token balance to observe that it has gone down to zero
liq_token_contract.query({"balance": {"address": str(wallet.address())}})
```

You can also check the full code example at [`liquidity-pool`](https://github.com/fetchai/cosmpy/blob/develop/examples/aerial_liquidity_pool.py)
You can also check the full code example at [`liquidity-pool`](https://github.com/fetchai/cosmpy/blob/develop/examples/aerial_liquidity_pool.py)
16 changes: 14 additions & 2 deletions docs/oracles.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ This guide shows how to write a CosmPy script that deploys and updates an oracle
## Preliminaries

We will need the binaries for both contracts, which can be downloaded as follows:

```bash
wget https://raw.githubusercontent.com/fetchai/agents-aea/develop/packages/fetchai/contracts/oracle/build/oracle.wasm
wget https://raw.githubusercontent.com/fetchai/agents-aea/develop/packages/fetchai/contracts/oracle_client/build/oracle_client.wasm
```

The scripts also require the following imports:

```python
from time import sleep
import requests
Expand All @@ -24,6 +26,7 @@ from cosmpy.crypto.keypairs import PrivateKey
## Oracle deployer and updater

We first choose a data source for the coin price, the update interval, and the decimal precision for the oracle value:

```python
COIN_PRICE_URL = (
"https://api.coingecko.com/api/v3/simple/price?ids=fetch-ai&vs_currencies=usd"
Expand All @@ -33,17 +36,20 @@ ORACLE_VALUE_DECIMALS = 5
```

Next, we create a wallet and ledger interface to interact with the latest stable testnet:

```python
wallet = LocalWallet(PrivateKey("T7w1yHq1QIcQiSqV27YSwk+i1i+Y4JMKhkpawCQIh6s="))
ledger = LedgerClient(NetworkConfig.fetchai_stable_testnet())
```

Create the `LedgerContract` object:

```python
contract = LedgerContract("oracle.wasm", ledger)
```

To deploy the oracle contract, add the fee amount to the instantiation message and call the `deploy` function:
To deploy the oracle contract, add the fee amount to the instantiation message and call the deploy function:

```python
instantiation_message = {"fee": "100"}
contract.deploy(instantiation_message, wallet, funds="1atestfet")
Expand All @@ -54,12 +60,14 @@ Save the oracle contract address to use for the oracle client script below (`ORA

As the deployer of the contract, we have permission to grant the oracle to a particular address.
In this case, we'll grant the oracle role to our own wallet:

```python
grant_role_message = {"grant_oracle_role": {"address": wallet)}}
contract.execute(grant_role_message, wallet).wait_to_complete()
```

Finally, start updating the contract with the coin price retrieved from the `COIN_PRICE_URL`:

```python
while True:
resp = requests.get(COIN_PRICE_URL).json()
Expand All @@ -84,24 +92,28 @@ For the complete example script, see [aerial_oracle.py](https://github.com/fetch
Now we'll write a script that deploys a contract that can request the oracle value in exchange for the required fee.

We again start by creating a wallet and ledger interface in a new terminal session:

```python
wallet = LocalWallet(PrivateKey("CI5AZQcr+FNl2usnSIQYpXsGWvBxKLRDkieUNIvMOV8="))
ledger = LedgerClient(NetworkConfig.fetchai_stable_testnet())
```

Set `ORACLE_CONTRACT_ADDRESS` to the address of the contract deployed in the previous script:

```python
ORACLE_CONTRACT_ADDRESS = "contract_address_goes_here"
```

Next, we define the contract object, set the oracle contract address in the instantiation message, and deploy the contract:

```python
contract = LedgerContract("oracle_client.wasm", ledger)
instantiation_message = {"oracle_contract_address": str(ORACLE_CONTRACT_ADDRESS)}
contract.deploy(instantiation_message, wallet)
```

Finally, define a request interval and start a loop that executes the function that requests the oracle value:

```python
REQUEST_INTERVAL_SECONDS = 10
while True:
Expand All @@ -114,4 +126,4 @@ while True:
sleep(REQUEST_INTERVAL_SECONDS)
```

For the complete example script, see [aerial_oracle_client.py](https://github.com/fetchai/cosmpy/blob/develop/examples/aerial_oracle_client.py).
For the complete example script, see [aerial_oracle_client.py](https://github.com/fetchai/cosmpy/blob/develop/examples/aerial_oracle_client.py).