Setup anonymous voting for a project.
Configures BLS12-381 cryptographic primitives for anonymous voting. Only the contract admin can call this function.
env - The environment objectproject_key - Unique identifier for the projectpublic_key - Asymmetric public key to be used for vote encryptionfn anonymous_voting_setup(
env: soroban_sdk::Env,
maintainer: soroban_sdk::Address,
project_key: soroban_sdk::Bytes,
public_key: soroban_sdk::String,
)
Get the anonymous voting configuration for a project.
env - The environment objectproject_key - The project key identifiertypes::AnonymousVoteConfig - The anonymous voting configurationfn get_anonymous_voting_config(
env: soroban_sdk::Env,
project_key: soroban_sdk::Bytes,
) -> AnonymousVoteConfig
Build vote commitments from votes and seeds for anonymous voting.
Creates BLS12-381 commitments for each vote using the formula: C = g^vote * h^seed where g and h are generator points.
Note: This function does not consider voting weights, which are applied during the tallying phase. Calling this on the smart contract would reveal the votes and seeds, so it must be run either in simulation or client-side.
env - The environment objectproject_key - Unique identifier for the projectvotes - Vector of vote choices (0=abstain, 1=approve, 2=reject)seeds - Vector of random seeds for each voteVec<BytesN<96>> - Vector of vote commitments (one per vote)fn build_commitments_from_votes(
env: soroban_sdk::Env,
project_key: soroban_sdk::Bytes,
votes: soroban_sdk::Vec,
seeds: soroban_sdk::Vec,
) -> soroban_sdk::Vec>
Create a new proposal for a project.
The proposer is automatically added to the abstain group. By creating a proposal, the proposer incur a collateral which is repaid upon execution of the proposal unless the proposal is revoked. This is a deterrent mechanism.
env - The environment objectproposer - Address of the proposal creatorproject_key - Unique identifier for the projecttitle - Title of the proposalipfs - IPFS content identifier describing the proposalvoting_ends_at - UNIX timestamp when voting endspublic_voting - Whether voting is public or anonymousOption<outcomes_contract>] - Outcome contract addressu32 - The ID of the created proposal.fn create_proposal(
env: soroban_sdk::Env,
proposer: soroban_sdk::Address,
project_key: soroban_sdk::Bytes,
title: soroban_sdk::String,
ipfs: soroban_sdk::String,
voting_ends_at: u64,
public_voting: bool,
outcomes_contract: Option,
) -> u32
Revoke a proposal.
Useful if there was some spam or bad intent. That will prevent the collateral to be claimed back.
env - The environment objectmaintainer - Address of the proposal creatorproject_key - The project key identifierproposal_id - The ID of the proposal to vote onfn revoke_proposal(
env: soroban_sdk::Env,
maintainer: soroban_sdk::Address,
project_key: soroban_sdk::Bytes,
proposal_id: u32,
)
Cast a vote on a proposal.
Allows a member to vote on a proposal. The vote can be either public or anonymous depending on the proposal configuration. For public votes, the choice and weight are visible. For anonymous votes, only the weight is visible, and the choice is encrypted.
env - The environment objectvoter - The address of the voterproject_key - The project key identifierproposal_id - The ID of the proposal to vote onvote - The vote data (public or anonymous)fn vote(
env: soroban_sdk::Env,
voter: soroban_sdk::Address,
project_key: soroban_sdk::Bytes,
proposal_id: u32,
vote: Vote,
)
Execute a vote after the voting period ends.
Processes the voting results and determines the final status of the proposal. For public votes, the results are calculated directly from vote counts. For anonymous votes, tallies and seeds are validated against vote commitments to ensure the results are correct.
env - The environment objectmaintainer - The address of the maintainer executing the proposalproject_key - The project key identifierproposal_id - The ID of the proposal to executeOption<tallies>] - decoded tally values (scaled by weights), respectively Approve, reject and abstainOption<seeds>] - decoded seed values (scaled by weights), respectively Approve, reject and abstaintypes::ProposalStatus - The final status of the proposal (Approved, Rejected, or Cancelled)fn execute(
env: soroban_sdk::Env,
maintainer: soroban_sdk::Address,
project_key: soroban_sdk::Bytes,
proposal_id: u32,
tallies: Option>,
seeds: Option>,
) -> ProposalStatus
Verify vote commitment proof for anonymous voting.
Validates that the provided tallies and seeds match the vote commitments without revealing individual votes. This ensures the integrity of anonymous voting results.
The commitment is:
C = g^v * h^r (in additive notation: gv + hr),
where g, h are BLS12-381 generator points and v is the vote choice, r is the seed. Voting weight is introduced during the tallying phase.
env - The environment objectproject_key - The project key identifierproposal - The proposal containing vote commitmentstallies - Decoded tally values [approve, reject, abstain] (scaled by weights)seeds - Decoded seed values [approve, reject, abstain] (scaled by weights)bool - True if all commitments match the provided tallies and seedsfn proof(
env: soroban_sdk::Env,
project_key: soroban_sdk::Bytes,
proposal: Proposal,
tallies: soroban_sdk::Vec,
seeds: soroban_sdk::Vec,
) -> bool
Returns a page of proposals (0 to MAX_PROPOSALS_PER_PAGE proposals per page).
env - The environment objectproject_key - The project key identifierpage - The page number (0-based)types::Dao - The DAO object containing a page of proposalsfn get_dao(env: soroban_sdk::Env, project_key: soroban_sdk::Bytes, page: u32) -> Dao
Get a single proposal by ID.
env - The environment objectproject_key - The project key identifierproposal_id - The ID of the proposal to retrievetypes::Proposal - The proposal objectfn get_proposal(
env: soroban_sdk::Env,
project_key: soroban_sdk::Bytes,
proposal_id: u32,
) -> Proposal
Add a new member to the system with metadata.
env - The environment objectmember_address - The address of the member to addmeta - Metadata string associated with the member (e.g., IPFS hash)fn add_member(
env: soroban_sdk::Env,
member_address: soroban_sdk::Address,
meta: soroban_sdk::String,
)
Get member information including all project badges.
env - The environment objectmember_address - The address of the member to retrievetypes::Member - Member information including metadata and project badgesfn get_member(env: soroban_sdk::Env, member_address: soroban_sdk::Address) -> Member
Set badges for a member in a specific project.
This function replaces all existing badges for the member in the specified project with the new badge list. The member's maximum voting weight is calculated as the sum of all assigned badge weights.
env - The environment objectmaintainer - The address of the maintainer (must be authorized)key - The project key identifiermember - The address of the member to set badges forbadges - Vector of badges to assignfn set_badges(
env: soroban_sdk::Env,
maintainer: soroban_sdk::Address,
key: soroban_sdk::Bytes,
member: soroban_sdk::Address,
badges: soroban_sdk::Vec,
)
Get all badges for a specific project, organized by badge type.
Returns a structure containing vectors of member addresses for each badge type (Developer, Triage, Community, Verified).
env - The environment objectkey - The project key identifiertypes::Badges - Structure containing member addresses for each badge typefn get_badges(env: soroban_sdk::Env, key: soroban_sdk::Bytes) -> Badges
Get the maximum voting weight for a member in a specific project.
Calculates the sum of all badge weights for the member in the project. If no badges are assigned, returns the Default badge weight (1). This weight determines the maximum number of votes the member can cast in a single voting transaction.
env - The environment objectproject_key - The project key identifiermember_address - The address of the memberu32 - The maximum voting weight for the memberfn get_max_weight(
env: soroban_sdk::Env,
project_key: soroban_sdk::Bytes,
member_address: soroban_sdk::Address,
) -> u32
Initialize the Tansu contract with admin configuration.
env - The environment objectadmin - The admin addressfn __constructor(env: soroban_sdk::Env, admin: soroban_sdk::Address)
Pause or unpause the contract (emergency stop.)
env - The environment objectadmin - The admin addresspaused - Pause or unpause the contract operations which change
ledger states.fn pause(env: soroban_sdk::Env, admin: soroban_sdk::Address, paused: bool)
Require that the contract is not paused, panic if it is
fn require_not_paused(env: soroban_sdk::Env)
Get current administrators configuration.
env - The environment objecttypes::AdminsConfig - The administrators configurationfn get_admins_config(env: soroban_sdk::Env) -> AdminsConfig
Set the Soroban Domain contract.
env - The environment objectadmin - The admin addressdomain_contract - The new domain contractfn set_domain_contract(
env: soroban_sdk::Env,
admin: soroban_sdk::Address,
domain_contract: Contract,
)
Set the Collateral contract.
env - The environment objectadmin - The admin addresscollateral_contract - The new collateral contractfn set_collateral_contract(
env: soroban_sdk::Env,
admin: soroban_sdk::Address,
collateral_contract: Contract,
)
Propose a contract upgrade.
env - The environment objectadmin - An admin addressnew_wasm_hash - The new WASM hashnew_admins_config - Optional new admin configuration (None to keep current)fn propose_upgrade(
env: soroban_sdk::Env,
admin: soroban_sdk::Address,
new_wasm_hash: soroban_sdk::BytesN<32>,
new_admins_config: Option,
)
Approve an upgrade proposal
env - The environment objectadmin - An admin addressfn approve_upgrade(env: soroban_sdk::Env, admin: soroban_sdk::Address)
Execute or cancel upgrade proposal
env - The environment objectadmin - An admin addressaccept - true to accept and false to reject.Upgrades can always be cancelled but only executed if there are enough approvals and the timelock period is over.
fn finalize_upgrade(env: soroban_sdk::Env, admin: soroban_sdk::Address, accept: bool)
Get upgrade proposal details
fn get_upgrade_proposal(env: soroban_sdk::Env) -> UpgradeProposal
Get the current version of the contract.
u32 - The contract version numberfn version(env: soroban_sdk::Env) -> u32
Register a new project.
Creates a new project entry with maintainers, URL, and commit hash. Also registers the project name in the domain contract if not already registered. The project key is generated using keccak256 hash of the project name.
env - The environment objectmaintainer - The address of the maintainer calling this functionname - The project name (max 15 characters)maintainers - List of maintainer addresses for the projecturl - The project's Git repository URLipfs - CID of the tansu.toml file with associated metadataBytes - The project key (keccak256 hash of the name)fn register(
env: soroban_sdk::Env,
maintainer: soroban_sdk::Address,
name: soroban_sdk::String,
maintainers: soroban_sdk::Vec,
url: soroban_sdk::String,
ipfs: soroban_sdk::String,
) -> soroban_sdk::Bytes
Update the configuration of an existing project.
Allows maintainers to change the project's URL, commit hash, and maintainer list.
env - The environment objectmaintainer - The address of the maintainer calling this functionkey - The project key identifiermaintainers - New list of maintainer addressesurl - New Git repository URLhash - New commit hashfn update_config(
env: soroban_sdk::Env,
maintainer: soroban_sdk::Address,
key: soroban_sdk::Bytes,
maintainers: soroban_sdk::Vec,
url: soroban_sdk::String,
ipfs: soroban_sdk::String,
)
Set the latest commit hash for a project.
Updates the current commit hash for the specified project.
env - The environment objectmaintainer - The address of the maintainer calling this functionproject_key - The project key identifierhash - The new commit hashfn commit(
env: soroban_sdk::Env,
maintainer: soroban_sdk::Address,
project_key: soroban_sdk::Bytes,
hash: soroban_sdk::String,
)
Get the last commit hash Get the latest commit hash for a project.
env - The environment objectproject_key - The project key identifierString - The current commit hashfn get_commit(
env: soroban_sdk::Env,
project_key: soroban_sdk::Bytes,
) -> soroban_sdk::String
Get project information including configuration and maintainers.
env - The environment objectproject_key - The project key identifiertypes::Project - Project information including name, config, and maintainersfn get_project(env: soroban_sdk::Env, project_key: soroban_sdk::Bytes) -> Project