Skip to content

Commit dd6b367

Browse files
committed
remove free functions, and add code snippet for votes integration
1 parent eae0129 commit dd6b367

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

content/stellar-contracts/governance/governor.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ A proposal succeeds when `for > against` **and** the quorum is reached. Quorum v
7575

7676
### Custom Counting Strategies
7777

78-
The counting logic is fully pluggable. The default three-type system works for most cases, but you can override the counting methods (`count_vote`, `tally_succeeded`, `quorum_reached`) to implement alternative strategies such as fractional voting, weighted quorum relative to total supply, or NFT-based voting schemes. The `counting_mode()` method returns a symbol identifying the active strategy, which UIs can use for display purposes.
78+
The counting logic is fully pluggable. The default three-type system works for most cases, but you can override the counting methods (`count_vote`, `tally_succeeded`, `quorum_reached`) to implement alternative strategies such as fractional voting or weighted quorum relative to total supply. The `counting_mode()` method returns a symbol identifying the active strategy, which UIs can use for display purposes.
7979

8080
### Dynamic Quorum
8181

content/stellar-contracts/governance/votes.mdx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ pub fn delegate(e: &Env, account: Address, delegatee: Address) {
6969

7070
<Callout>
7171
If you are using the Fungible or Non-Fungible token from this library, the **Votes extension** handles all of this automatically. You only need to enable the extension — no manual integration required. See [Fungible Token](/stellar-contracts/tokens/fungible/fungible) or [Non-Fungible Token](/stellar-contracts/tokens/non-fungible/non-fungible).
72+
73+
```rust
74+
use stellar_governance::votes::Votes;
75+
use stellar_tokens::fungible::{votes::FungibleVotes, FungibleToken};
76+
77+
// 1. Set ContractType to FungibleVotes — this hooks into all balance
78+
// changes (transfers, mints, burns) and updates voting units automatically.
79+
#[contractimpl(contracttrait)]
80+
impl FungibleToken for MyToken {
81+
type ContractType = FungibleVotes;
82+
}
83+
84+
// 2. Implement the Votes trait to expose voting queries to the Governor.
85+
#[contractimpl(contracttrait)]
86+
impl Votes for MyToken {}
87+
```
7288
</Callout>
7389

7490
## The Votes Trait
@@ -100,18 +116,6 @@ pub trait Votes {
100116

101117
All query methods return `0` if the account has no voting power or does not exist.
102118

103-
## Free Functions
104-
105-
In addition to the trait, the module exports free functions for lower-level use:
106-
107-
| Function | Description |
108-
|----------|-------------|
109-
| `transfer_voting_units(e, from, to, amount)` | Updates voting units on balance changes. `from`/`to` are `Option<&Address>` for mint/burn. |
110-
| `get_voting_units(e, account)` | Returns the raw voting units (not delegated votes) for an account. |
111-
| `get_checkpoint(e, account, pos)` | Returns a specific checkpoint by position index. |
112-
| `num_checkpoints(e, account)` | Returns the number of checkpoints for an account. |
113-
| `delegate(e, account, delegatee)` | Delegates voting power. Requires authorization from `account`. |
114-
115119
## See Also
116120

117121
- [Governor](/stellar-contracts/governance/governor)

0 commit comments

Comments
 (0)