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
InstantiateMsg
Rust JSON
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
pub struct InstantiateMsg {
pub quorum : Decimal ,
pub threshold : Decimal ,
pub voting_period : u64 ,
pub timelock_period : u64 ,
pub expiration_period : u64 ,
pub proposal_deposit : Uint128 ,
pub snapshot_period : u64 ,
}
Copy {
"quorum" : "0.1" ,
"threshold" : "0.5" ,
"voting_period" : 123456 ,
"timelock_period" : 123456 ,
"expiration_period" : 123456 ,
"proposal_deposit" : "100000000" ,
"snapshot_period" : 123456
}
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
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum ExecuteMsg {
Receive {
sender : String ,
amount : Uint128 ,
msg : Binary ,
}
}
Copy {
"receive" : {
"amount" : "10000000" ,
"sender" : "terra1..." ,
"msg" : "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
}
}
[Internal] ExecutePollMsgs
Executes messages in a passed poll. Can only by issued by Gov
.
Rust JSON
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum ExecuteMsg {
ExecutePollMsgs {
poll_id : u64 ,
}
}
Copy {
"execute_poll_msgs" : {
"poll_id" : 8
}
}
RegisterContracts
Registers the contract addresses (i.e. Anchor Token, ANC) to Gov.
Rust JSON
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum ExecuteMsg {
RegisterContracts {
anchor_token : String ,
}
}
Copy {
"register_contracts" : {
"anchor_token" : "terra1..." ,
}
}
UpdateConfig
Updates the configuration of the Gov contract.
Rust JSON
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum ExecuteMsg {
UpdateConfig {
owner : Option < String >,
quorum : Option < Decimal >,
threshold : Option < Decimal >,
voting_period : Option < u64 >,
timelock_period : Option < u64 >,
expiration_period : Option < u64 >,
proposal_deposit : Option < Uint128 >,
snapshot_period : Option < u64 >,
}
}
Copy {
"update_config" : {
"owner" : "terra1..." ,
"quorum" : "0.1" ,
"threshold" : "0.1" ,
"voting_period" : 123456 ,
"timelock_period" : 123456 ,
"expiration_period" : 123456 ,
"proposal_deposit" : "100000000" ,
"snapshot_period" : 123456
}
}
* = 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
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum ExecuteMsg {
CastVote {
poll_id : u64 ,
vote : VoteOption ,
amount : Uint128 ,
}
}
#[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum VoteOption {
Yes ,
No ,
}
Copy {
"cast_vote" : {
"poll_id" : 8 ,
"vote" : "yes" ,
"amount" : "10000000"
}
}
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
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum ExecuteMsg {
WithdrawVotingTokens {
amount : Option < Uint128 >,
}
}
Copy {
"withdraw_voting_tokens" : {
"amount" : "100000000"
}
}
* = 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
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum ExecuteMsg {
EndPoll {
poll_id : u64 ,
}
}
Copy {
"end_poll" : {
"poll_id" : 8
}
}
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
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum ExecuteMsg {
ExecutePoll {
poll_id : u64 ,
}
}
Copy {
"execute_poll" : {
"poll_id" : 8
}
}
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
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum ExecuteMsg {
SnapshotPoll {
poll_id : u64 ,
}
}
Copy {
"snapshot_poll" : {
"poll_id" : 8
}
}
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
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum Cw20HookMsg {
StakeVotingTokens {}
}
Copy {
"stake_voting_tokens" : {}
}
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
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum Cw20HookMsg {
CreatePoll {
title : String ,
description : String ,
link : Option < String >,
execute_msgs : Option < Vec < PollExecuteMsg >>,
}
}
#[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub struct PollExecuteMsg {
pub order : u64 ,
pub contract : String ,
pub msg : Binary ,
}
Copy {
"create_poll" : {
"title" : "..." ,
"description" : "..." ,
"link" : "https://..." ,
"execute_msgs" : [
{
"order" : 1 ,
"contract" : "terra1..." ,
"msg" : "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
} ,
{
"order" : 2 ,
"contract" : "terra1..." ,
"msg" : "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
}
]
}
}
* = optional
QueryMsg
Config
Gets the configuration for the Gov contract.
Rust JSON
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum QueryMsg {
Config {}
}
ConfigResponse
Rust JSON
Copy #[derive( Serialize , Deserialize , Clone , PartialEq , JsonSchema )]
pub struct ConfigResponse {
pub owner : String ,
pub anchor_token : String ,
pub quorum : Decimal ,
pub threshold : Decimal ,
pub voting_period : u64 ,
pub timelock_period : u64 ,
pub expiration_period : u64 ,
pub proposal_deposit : Uint128 ,
pub snapshot_period : u64 ,
}
Copy {
"owner" : "terra1..." ,
"anchor_token" : "terra1..." ,
"quorum" : "0.1" ,
"threshold" : "0.5" ,
"voting_period" : 123456 ,
"timelock_period" : 123456 ,
"expiration_period" : 123456 ,
"proposal_deposit" : "100000000" ,
"snapshot_period" : 123456
}
State
Gets state information for the Gov contract.
Rust JSON
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum QueryMsg {
State {}
}
StateResponse
Rust JSON
Copy #[derive( Serialize , Deserialize , Clone , PartialEq , JsonSchema )]
pub struct StateResponse {
pub poll_count : u64 ,
pub total_share : Uint128 ,
pub total_deposit : Uint128 ,
}
Copy {
"poll_count" : 8 ,
"total_share" : "100000000" ,
"total_deposit" : "100000000"
}
Staker
Gets information for the specified ANC staker.
Rust JSON
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum QueryMsg {
Staker {
address : String ,
}
}
Copy {
"staker" : {
"address" : "terra1..."
}
}
StakerResponse
Rust JSON
Copy #[derive( Serialize , Deserialize , Debug , Clone , PartialEq , JsonSchema )]
pub struct StakerResponse {
pub balance : Uint128 ,
pub share : Uint128 ,
pub locked_balance : Vec <( u64 , VoterInfo )>, // (Voted Poll's ID, VoterInfo)
}
#[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
pub struct VoterInfo {
pub vote : VoteOption ,
pub balance : Uint128 ,
}
#[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum VoteOption {
Yes ,
No ,
}
Copy {
"balance" : "100000000" ,
"share" : "100000000" ,
"locked_balance" : [
[
7 ,
{
"vote" : "yes" ,
"balance" : "100000000"
}
] ,
[
8 ,
{
"vote" : "no" ,
"balance" : "100000000"
}
]
]
}
Poll
Gets information for the specified poll.
Rust JSON
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum QueryMsg {
Poll {
poll_id : u64 ,
}
}
Copy {
"poll" : {
"poll_id" : 8
}
}
PollResponse
Rust JSON
Copy #[derive( Serialize , Deserialize , Debug , Clone , PartialEq , JsonSchema )]
pub struct PollResponse {
pub id : u64 ,
pub creator : String ,
pub status : PollStatus ,
pub end_height : u64 ,
pub title : String ,
pub description : String ,
pub link : Option < String >,
pub deposit_amount : Uint128 ,
pub execute_data : Option < PollExecuteMsg >,
pub yes_votes : Uint128 , // balance
pub no_votes : Uint128 , // balance
pub staked_amount : Option < Uint128 >,
pub total_balance_at_end_poll : Option < Uint128 >,
}
#[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum PollStatus {
InProgress ,
Passed ,
Rejected ,
Executed ,
Expired , // Deprecated
Failed ,
}
#[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub struct ExecuteMsg {
pub order : u64 ,
pub contract : String ,
pub msg : Binary ,
}
Copy {
"id" : 8 ,
"creator" : "terra1..." ,
"status" : "executed" ,
"end_height" : 123456 ,
"title" : "..." ,
"description" : "..." ,
"link" : "https://..." ,
"deposit_amount" : "100000000" ,
"execute_data" : [
{
"order" : 1 ,
"contract" : "terra1..." ,
"msg" : "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
} ,
{
"order" : 2 ,
"contract" : "terra1..." ,
"msg" : "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
}
] ,
"yes_votes" : "100000000" ,
"no_votes" : "100000000" ,
"staked_amount" : "100000000" ,
"total_balance_at_end_poll" : "100000000"
}
* = optional
Polls
Gets information for all polls.
Rust JSON
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum QueryMsg {
Polls {
filter : Option < PollStatus >,
start_after : Option < u64 >,
limit : Option < u32 >,
order_by : Option < OrderBy >,
}
}
#[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum PollStatus {
InProgress ,
Passed ,
Rejected ,
Executed ,
Expired , // Deprecated
Failed ,
}
#[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum OrderBy {
Asc ,
Desc ,
}
Copy {
"polls" : {
"filter" : "passed" ,
"start_after" : 8 ,
"limit" : 8 ,
"order_by" : "asc"
}
}
* = optional
PollsResponse
Rust JSON
Copy #[derive( Serialize , Deserialize , Debug , Clone , PartialEq , JsonSchema )]
pub struct PollsResponse {
pub polls : Vec < PollResponse >,
}
#[derive( Serialize , Deserialize , Debug , Clone , PartialEq , JsonSchema )]
pub struct PollResponse {
pub id : u64 ,
pub creator : String ,
pub status : PollStatus ,
pub end_height : u64 ,
pub title : String ,
pub description : String ,
pub link : Option < String >,
pub deposit_amount : Uint128 ,
pub execute_data : Option < PollExecuteMsg >,
pub yes_votes : Uint128 , // balance
pub no_votes : Uint128 , // balance
pub staked_amount : Option < Uint128 >,
pub total_balance_at_end_poll : Option < Uint128 >,
}
#[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum PollStatus {
InProgress ,
Passed ,
Rejected ,
Executed ,
Expired , // Deprecated
Failed ,
}
#[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub struct PollExecuteMsg {
pub order : u32 ,
pub contract : String ,
pub msg : Binary ,
}
Copy {
"polls" : [
{
"id" : 7 ,
"creator" : "terra1..." ,
"status" : "passed" ,
"end_height" : 123456 ,
"title" : "..." ,
"description" : "..." ,
"link" : "https://..." ,
"deposit_amount" : "100000000" ,
"execute_data" : [
{
"contract" : "terra1..." ,
"msg" : "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
} ,
{
"contract" : "terra1..." ,
"msg" : "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
}
] ,
"yes_votes" : "100000000" ,
"no_votes" : "100000000" ,
"staked_amount" : "100000000" ,
"total_balance_at_end_poll" : "100000000"
} ,
{
"id" : 8 ,
"creator" : "terra1..." ,
"status" : "executed" ,
"end_height" : 123456 ,
"title" : "..." ,
"description" : "..." ,
"link" : "https://..." ,
"deposit_amount" : "100000000" ,
"execute_data" : [
{
"order" : 1 ,
"contract" : "terra1..." ,
"msg" : "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
} ,
{
"order" : 2 ,
"contract" : "terra1..." ,
"msg" : "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
}
] ,
"yes_votes" : "100000000" ,
"no_votes" : "100000000" ,
"staked_amount" : "100000000" ,
"total_balance_at_end_poll" : "100000000"
}
]
}
* = optional
Voters
Gets voter information of the poll with the specified ID.
Rust JSON
Copy #[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum QueryMsg {
Voters {
poll_id : u64 ,
start_after : Option < String >,
limit : Option < u32 >,
order_by : Option < OrderBy >,
}
}
Copy {
"voters" : {
"poll_id" : 8 ,
"start_after" : "terra1.." ,
"limit" : 8 ,
"order_by" : "asc"
}
}
* = optional
VotersResponse
Rust JSON
Copy #[derive( Serialize , Deserialize , Debug , Clone , PartialEq , JsonSchema )]
pub struct VotersResponse {
pub voters : Vec < VotersResponseItem >,
}
#[derive( Serialize , Deserialize , Debug , Clone , PartialEq , JsonSchema )]
pub struct VotersResponseItem {
pub voter : String ,
pub vote : VoteOption ,
pub balance : Uint128 ,
}
#[derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema )]
#[serde(rename_all = "snake_case" )]
pub enum VoteOption {
Yes ,
No ,
}
Copy {
"voters" : [
{
"voter" : "terra1..." ,
"vote" : "yes" ,
"balance" : "100000000"
} ,
{
"voter" : "terra1..." ,
"vote" : "no" ,
"balance" : "100000000"
}