Gov
The Gov Contract contains logic for holding governance polls and handling Anchor Token (ANC) staking, and allows Anchor Protocol to be governed by its users in a decentralized manner. After the initial bootstrapping of Anchor Protocol's contracts, the Gov Contract is assigned to be the owner of all contracts in Anchor Protocol.
New proposals for change are submitted as polls, and are voted on by ANC stakers through the voting procedure. Polls can contain messages that can be executed directly without changing the Anchor Protocol code.
The Gov Contract keeps a balance of ANC tokens, which it uses to reward stakers with funds it receives from trading fees sent by the Anchor Collector and user deposits from creating new governance polls. This balance is separate from the Community Pool, which is held by the Community contract (owned by the Gov contract).

Config

Key
Type
Description
owner
CanonicalAddr
Address of contract owner
anchor_token
CanonicalAddr
Contract address of Anchor Token (ANC)
quorum
Decimal
Minimum percentage of participation required for a poll to pass
threshold
Decimal
Minimum percentage of yes votes required for a poll to pass
voting_period
u64
Number of blocks during which votes can be cast [blocks]
timelock_period
u64
Number of blocks required after a poll pass before executing changes [blocks]
expiration_period
u64
Number of blocks after a poll's voting period during which the poll can be executed [blocks]
proposal_deposit
Uint128
Minimum ANC deposit required for submitting a new poll
snapshot_period
u64
Window of time (number of blocks) allowed for poll snapshot before a poll's end [blocks]

InstantiateMsg

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct InstantiateMsg {
3
pub quorum: Decimal,
4
pub threshold: Decimal,
5
pub voting_period: u64,
6
pub timelock_period: u64,
7
pub expiration_period: u64,
8
pub proposal_deposit: Uint128,
9
pub snapshot_period: u64,
10
}
Copied!
1
{
2
"quorum": "0.1",
3
"threshold": "0.5",
4
"voting_period": 123456,
5
"timelock_period": 123456,
6
"expiration_period": 123456,
7
"proposal_deposit": "100000000",
8
"snapshot_period": 123456
9
}
Copied!
Key
Type
Description
quorum
Decimal
Minimum percentage of participation required for a poll to pass
threshold
Decimal
Minimum percentage of yes votes required for a poll to pass
voting_period
u64
Number of blocks during which votes can be cast [blocks]
timelock_period
u64
Number of blocks required after a poll pass before executing changes [blocks]
expiration_period
u64
Number of blocks after a poll's voting period during which the poll can be executed [blocks]
proposal_deposit
Uint128
Minimum ANC deposit required for submitting a new poll
snapshot_period
u64
Window of time (number of blocks) allowed for poll snapshot before a poll's end [blocks]

ExecuteMsg

Receive

Can be called during a CW20 token transfer when the Gov contract is the recipient. Allows the token transfer to execute a Receive Hook as a subsequent action within the same transaction.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
Receive {
5
sender: String,
6
amount: Uint128,
7
msg: Binary,
8
}
9
}
Copied!
1
{
2
"receive": {
3
"amount": "10000000",
4
"sender": "terra1...",
5
"msg": "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
6
}
7
}
Copied!
Key
Type
Description
sender
String
Sender of token transfer
amount
Uint128
Amount of tokens received
msg
Binary
Base64-encoded JSON of Receive Hook

[Internal] ExecutePollMsgs

Executes messages in a passed poll. Can only by issued by Gov.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
ExecutePollMsgs {
5
poll_id: u64,
6
}
7
}
Copied!
1
{
2
"execute_poll_msgs": {
3
"poll_id": 8
4
}
5
}
Copied!
Key
Type
Description
poll_id
u64
Poll ID

RegisterContracts

Registers the contract addresses (i.e. Anchor Token, ANC) to Gov.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
RegisterContracts {
5
anchor_token: String,
6
}
7
}
Copied!
1
{
2
"register_contracts": {
3
"anchor_token": "terra1...",
4
}
5
}
Copied!
Key
Type
Description
anchor_token
String
Contract address of Anchor Token (ANC)

UpdateConfig

Updates the configuration of the Gov contract.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
UpdateConfig {
5
owner: Option<String>,
6
quorum: Option<Decimal>,
7
threshold: Option<Decimal>,
8
voting_period: Option<u64>,
9
timelock_period: Option<u64>,
10
expiration_period: Option<u64>,
11
proposal_deposit: Option<Uint128>,
12
snapshot_period: Option<u64>,
13
}
14
}
Copied!
1
{
2
"update_config": {
3
"owner": "terra1...",
4
"quorum": "0.1",
5
"threshold": "0.1",
6
"voting_period": 123456,
7
"timelock_period": 123456,
8
"expiration_period": 123456,
9
"proposal_deposit": "100000000",
10
"snapshot_period": 123456
11
}
12
}
Copied!
Key
Type
Description
owner*
String
New address of contract owner
quorum*
Decimal
New percentage of participation (of total staked ANC) required for a poll to pass
threshold*
Decimal
New percentage of yes votes required for a poll to pass
voting_period*
u64
New number of blocks during which votes for a poll can be cast after it has finished its deposit [blocks]
timelock_period*
u64
New number of blocks required after a poll pass before executing changes [blocks]
expiration_period*
u64
New number of blocks after a poll's voting period during which the poll can be executed [blocks]
proposal_deposit*
Uint128
New minimum ANC deposit required for a poll to enter voting
snapshot_period*
u64
New window of time (number of blocks) allowed for poll snapshot before a poll's end [blocks]
* = optional

CastVote

Submits a user's vote for an active poll. Once a user has voted, they cannot change their vote with subsequent messages (increasing voting power, changing vote option, cancelling vote, etc.)
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
CastVote {
5
poll_id: u64,
6
vote: VoteOption,
7
amount: Uint128,
8
}
9
}
10
11
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
12
#[serde(rename_all = "snake_case")]
13
pub enum VoteOption {
14
Yes,
15
No,
16
}
Copied!
1
{
2
"cast_vote": {
3
"poll_id": 8,
4
"vote": "yes",
5
"amount": "10000000"
6
}
7
}
Copied!
Key
Type
Description
poll_id
u64
Poll ID
vote
VoteOption
Can be yes or no
amount
Uint128
Amount of voting power (staked ANC) to allocate

WithdrawVotingTokens

Removes specified amount of staked ANC tokens from a staking position and returns them to a user's balance. Withdraws all staked ANC tokens if amount is not specified.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
WithdrawVotingTokens {
5
amount: Option<Uint128>,
6
}
7
}
Copied!
1
{
2
"withdraw_voting_tokens": {
3
"amount": "100000000"
4
}
5
}
Copied!
Key
Type
Description
amount*
Uint128
Amount of ANC tokens to withdraw
* = optional

EndPoll

Can be issued by anyone to end the voting for an active poll. Triggers tally the results to determine whether the poll has passed. The current block height must exceed the end height of voting phase.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
EndPoll {
5
poll_id: u64,
6
}
7
}
Copied!
1
{
2
"end_poll": {
3
"poll_id": 8
4
}
5
}
Copied!
Key
Type
Description
poll_id
u64
Poll ID

ExecutePoll

Can be issued by anyone to implement into action the contents of a passed poll. The current block height must exceed the end height of the poll's effective delay.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
ExecutePoll {
5
poll_id: u64,
6
}
7
}
Copied!
1
{
2
"execute_poll": {
3
"poll_id": 8
4
}
5
}
Copied!
Key
Type
Description
poll_id
u64
Poll ID

SnapshotPoll

Snapshots the total amount of staked ANC and stores the number to the specified poll. This staked ANC amount is used to determine the degree of participation for this poll, calculated by dividing the total amount of ANC voted to the poll with the total staked ANC supply at the time of EndPoll. Can only be issued within a window of snapshot_period blocks before the poll's end_height.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
SnapshotPoll {
5
poll_id: u64,
6
}
7
}
Copied!
1
{
2
"snapshot_poll": {
3
"poll_id": 8
4
}
5
}
Copied!
Key
Type
Description
poll_id
u64
Poll ID

Receive Hooks

StakeVotingTokens

WARNING Sending ANC tokens to the Gov contract without issuing this hook will lead to PERMANENT LOSS OF FUNDS and will be irrevocably donated to the reward pool for stakers.
Issued when sending ANC tokens to the Gov contract to add them to their ANC staking position.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum Cw20HookMsg {
4
StakeVotingTokens {}
5
}
Copied!
1
{
2
"stake_voting_tokens": {}
3
}
Copied!
Key
Type
Description

CreatePoll

Issued when sending ANC tokens to the Gov contract to create a new poll. Will only succeed if the amount of tokens sent meets the configured proposal_deposit amount. Can contain a list of generic messages to be issued by the Gov contract if it passes (can invoke messages in other contracts it owns).
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum Cw20HookMsg {
4
CreatePoll {
5
title: String,
6
description: String,
7
link: Option<String>,
8
execute_msgs: Option<Vec<PollExecuteMsg>>,
9
}
10
}
11
12
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
13
#[serde(rename_all = "snake_case")]
14
pub struct PollExecuteMsg {
15
pub order: u64,
16
pub contract: String,
17
pub msg: Binary,
18
}
Copied!
1
{
2
"create_poll": {
3
"title": "...",
4
"description": "...",
5
"link": "https://...",
6
"execute_msgs": [
7
{
8
"order": 1,
9
"contract": "terra1...",
10
"msg": "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
11
},
12
{
13
"order": 2,
14
"contract": "terra1...",
15
"msg": "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
16
}
17
]
18
}
19
}
Copied!
Key
Type
Description
title
String
Poll title
description
String
Poll description
link*
String
URL to external post about poll (forum, PDF, etc.)
execute_msgs*
Vec<PollExecuteMsg>
List of governance messages to be issued by Gov contract upon poll execution
Key
Type
Description
order
u64
Order sequence of message
contract
String
Contract address of governance message recipient
msg
Binary
Base64-encoded JSON of governance message
* = optional

QueryMsg

Config

Gets the configuration for the Gov contract.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
Config {}
5
}
Copied!
1
{
2
"config": {}
3
}
Copied!
Key
Type
Description

ConfigResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema)]
2
pub struct ConfigResponse {
3
pub owner: String,
4
pub anchor_token: String,
5
pub quorum: Decimal,
6
pub threshold: Decimal,
7
pub voting_period: u64,
8
pub timelock_period: u64,
9
pub expiration_period: u64,
10
pub proposal_deposit: Uint128,
11
pub snapshot_period: u64,
12
}
Copied!
1
{
2
"owner": "terra1...",
3
"anchor_token": "terra1...",
4
"quorum": "0.1",
5
"threshold": "0.5",
6
"voting_period": 123456,
7
"timelock_period": 123456,
8
"expiration_period": 123456,
9
"proposal_deposit": "100000000",
10
"snapshot_period": 123456
11
}
Copied!
Key
Type
Description
owner
String
Address of contract owner
anchor_token
String
Contract address of Anchor Token (ANC)
quorum
Decimal
Minimum percentage of participation required for a poll to pass
threshold
Decimal
Minimum percentage of yes votes required for a poll to pass
voting_period
u64
Number of blocks during which votes can be cast [blocks]
timelock_period
u64
Number of blocks required after a poll pass before executing changes [blocks]
expiration_period
u64
Number of blocks after a poll's voting period during which the poll can be executed [blocks]
proposal_deposit
Uint128
Minimum ANC deposit required for submitting a new poll
snapshot_period
u64
Window of time (number of blocks) allowed for poll snapshot before a poll's end [blocks]

State

Gets state information for the Gov contract.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
State {}
5
}
Copied!
1
{
2
"state": {}
3
}
Copied!
Key
Type
Description

StateResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema)]
2
pub struct StateResponse {
3
pub poll_count: u64,
4
pub total_share: Uint128,
5
pub total_deposit: Uint128,
6
}
Copied!
1
{
2
"poll_count": 8,
3
"total_share": "100000000",
4
"total_deposit": "100000000"
5
}
Copied!
Key
Type
Description
poll_count
u64
Total number of created polls
total_share
Uint128
Current total number of voting shares
total_deposit
Uint128
Total amount of ANC currently deposited for poll creation

Staker

Gets information for the specified ANC staker.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
Staker {
5
address: String,
6
}
7
}
Copied!
1
{
2
"staker": {
3
"address": "terra1..."
4
}
5
}
Copied!
Key
Type
Description
address
String
Address of staker

StakerResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
2
pub struct StakerResponse {
3
pub balance: Uint128,
4
pub share: Uint128,
5
pub locked_balance: Vec<(u64, VoterInfo)>, // (Voted Poll's ID, VoterInfo)
6
}
7
8
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
9
pub struct VoterInfo {
10
pub vote: VoteOption,
11
pub balance: Uint128,
12
}
13
14
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
15
#[serde(rename_all = "snake_case")]
16
pub enum VoteOption {
17
Yes,
18
No,
19
}
Copied!
1
{
2
"balance": "100000000",
3
"share": "100000000",
4
"locked_balance": [
5
[
6
7,
7
{
8
"vote": "yes",
9
"balance": "100000000"
10
}
11
],
12
[
13
8,
14
{
15
"vote": "no",
16
"balance": "100000000"
17
}
18
]
19
]
20
}
Copied!
Key
Type
Description
balance
Uint128
Amount of ANC staked by staker
share
Uint128
Total voting shares owned by staker
locked_balance
Vec<(u64, VoterInfo)>
List of (voted poll's ID, voter's vote information)
Name
Type
Description
vote
VoteOption
Vote type made by staker
balance
Uint128
Amount of staked ANC locked to vote this poll
Name
Description
yes
Staker has voted for the proposal
no
Staker has voted against the proposal

Poll

Gets information for the specified poll.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
Poll {
5
poll_id: u64,
6
}
7
}
Copied!
1
{
2
"poll": {
3
"poll_id": 8
4
}
5
}
Copied!
Key
Type
Description
poll_id
u64
Poll ID

PollResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
2
pub struct PollResponse {
3
pub id: u64,
4
pub creator: String,
5
pub status: PollStatus,
6
pub end_height: u64,
7
pub title: String,
8
pub description: String,
9
pub link: Option<String>,
10
pub deposit_amount: Uint128,
11
pub execute_data: Option<PollExecuteMsg>,
12
pub yes_votes: Uint128, // balance
13
pub no_votes: Uint128, // balance
14
pub staked_amount: Option<Uint128>,
15
pub total_balance_at_end_poll: Option<Uint128>,
16
}
17
18
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
19
#[serde(rename_all = "snake_case")]
20
pub enum PollStatus {
21
InProgress,
22
Passed,
23
Rejected,
24
Executed,
25
Expired, // Deprecated
26
Failed,
27
}
28
29
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
30
#[serde(rename_all = "snake_case")]
31
pub struct ExecuteMsg {
32
pub order: u64,
33
pub contract: String,
34
pub msg: Binary,
35
}
Copied!
1
{
2
"id": 8,
3
"creator": "terra1...",
4
"status": "executed",
5
"end_height": 123456,
6
"title": "...",
7
"description": "...",
8
"link": "https://...",
9
"deposit_amount": "100000000",
10
"execute_data": [
11
{
12
"order": 1,
13
"contract": "terra1...",
14
"msg": "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
15
},
16
{
17
"order": 2,
18
"contract": "terra1...",
19
"msg": "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
20
}
21
],
22
"yes_votes": "100000000",
23
"no_votes": "100000000",
24
"staked_amount": "100000000",
25
"total_balance_at_end_poll": "100000000"
26
}
Copied!
Key
Type
Description
id
u64
Poll ID
creator
String
Poll creator
status
PollStatus
Current poll status
end_height
u64
Block number when voting for this poll closes [block]
title
String
Poll title
description
String
Poll description
link*
String
URL to external post about poll (forum, PDF, etc.)
deposit_amount
Uint128
ANC deposit used to submit poll
execute_data*
Vec<PollExecuteMsg>
List of governance messages to be issued upon poll execution
yes_votes
Uint128
Total yes votes (staked ANC amount) for this poll
no_votes
Uint128
Total no votes (staked ANC amount) for this poll
staked_amount*
Uint128
Total staked ANC amount at time of poll snapshot
total_balance_at_end_poll*
Uint128
Total staked ANC amount at the end of this poll
Key
Description
InProgress
Voting for this poll is currently in progress
Passed
This poll has been passed by governance
Rejected
This poll has been rejected by governance
Executed
This poll has been passed by governance and executed
Expired
This poll has been expired after rejection / execution [Deprecated]
Failed
This poll has been passed, but failed to execute
Key
Type
Description
order
u64
Order sequence of message
contract
String
Contract address of governance message recipient
msg
Binary
Base64-encoded JSON governance message
* = optional

Polls

Gets information for all polls.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
Polls {
5
filter: Option<PollStatus>,
6
start_after: Option<u64>,
7
limit: Option<u32>,
8
order_by: Option<OrderBy>,
9
}
10
}
11
12
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
13
#[serde(rename_all = "snake_case")]
14
pub enum PollStatus {
15
InProgress,
16
Passed,
17
Rejected,
18
Executed,
19
Expired, // Deprecated
20
Failed,
21
}
22
23
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
24
#[serde(rename_all = "snake_case")]
25
pub enum OrderBy {
26
Asc,
27
Desc,
28
}
Copied!
1
{
2
"polls": {
3
"filter": "passed",
4
"start_after": 8,
5
"limit": 8,
6
"order_by": "asc"
7
}
8
}
Copied!
Key
Type
Description
filter*
PollStatus
Poll statuses to search for
start_after*
u64
Poll ID to start query at
limit*
u32
Maximum number of query entries
order_by*
OrderBy
Order to make query
Key
Description
InProgress
Poll is currently in voting period
Passed
Poll has been passed by governance
Rejected
Poll has been rejected by governance
Executed
Poll has been passed and executed by governance
Expired
Poll has been expired after rejection / execution [Deprecated]
Failed
Poll has been passed, but failed to execute
Key
Description
Asc
Make query in ascending order
Desc
Make query in descending order
* = optional

PollsResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
2
pub struct PollsResponse {
3
pub polls: Vec<PollResponse>,
4
}
5
6
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
7
pub struct PollResponse {
8
pub id: u64,
9
pub creator: String,
10
pub status: PollStatus,
11
pub end_height: u64,
12
pub title: String,
13
pub description: String,
14
pub link: Option<String>,
15
pub deposit_amount: Uint128,
16
pub execute_data: Option<PollExecuteMsg>,
17
pub yes_votes: Uint128, // balance
18
pub no_votes: Uint128, // balance
19
pub staked_amount: Option<Uint128>,
20
pub total_balance_at_end_poll: Option<Uint128>,
21
}
22
23
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
24
#[serde(rename_all = "snake_case")]
25
pub enum PollStatus {
26
InProgress,
27
Passed,
28
Rejected,
29
Executed,
30
Expired, // Deprecated
31
Failed,
32
}
33
34
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
35
#[serde(rename_all = "snake_case")]
36
pub struct PollExecuteMsg {
37
pub order: u32,
38
pub contract: String,
39
pub msg: Binary,
40
}