#weight #role #contract #on-chain #nft #dao #voting

cw721-roles

Non-transferable CW721 NFT contract that incorporates voting weights and on-chain roles

6 stable releases

2.6.0 Nov 7, 2024
2.5.0 Oct 31, 2024
2.4.2 Jul 22, 2024
2.4.0 Jul 21, 2024
2.3.0 Oct 18, 2023

#965 in Magic Beans

Download history 65/week @ 2024-07-27 3/week @ 2024-08-03 6/week @ 2024-09-21 5/week @ 2024-09-28 125/week @ 2024-10-26 120/week @ 2024-11-02 27/week @ 2024-11-09

272 downloads per month
Used in 2 crates (via dao-testing)

BSD-3-Clause

46KB
954 lines

cw721-roles

This is a non-transferable NFT contract intended for use with DAOs. cw721-roles has an extension that allows for each NFT to have a weight associated with it, and also implements much of the functionality behind the cw4-group contract (credit to Confio for their work on that).

All methods of this contract are only callable via the configurable minter when the contract is created. It is primarily intended for use with DAOs.

The mint, burn, send, and transfer methods have all been overriden from their default cw721-base versions, but work roughly the same with the caveat being they are only callable via the minter. All methods related to approvals are unsupported.

Extensions

cw721-roles contains the following extensions:

Token metadata has been extended with a weight and an optional human readable on-chain role which may be used in separate contracts for enforcing additional permissions.

pub struct MetadataExt {
    /// Optional on-chain role for this member, can be used by other contracts to enforce permissions
    pub role: Option<String>,
    /// The voting weight of this role
    pub weight: u64,
}

The contract has an additional execution extension that includes the ability to add and remove hooks for membership change events, as well as update a particular token's token_uri, weight, and role. All of these are only callable by the configured minter.

pub enum ExecuteExt {
    /// Add a new hook to be informed of all membership changes.
    /// Must be called by Admin
    AddHook { addr: String },
    /// Remove a hook. Must be called by Admin
    RemoveHook { addr: String },
    /// Update the token_uri for a particular NFT. Must be called by minter / admin
    UpdateTokenUri {
        token_id: String,
        token_uri: Option<String>,
    },
    /// Updates the voting weight of a token. Must be called by minter / admin
    UpdateTokenWeight { token_id: String, weight: u64 },
    /// Udates the role of a token. Must be called by minter / admin
    UpdateTokenRole {
        token_id: String,
        role: Option<String>,
    },
}

The query extension implements queries that are compatible with the previously mentioned cw4-group contract.

pub enum QueryExt {
    /// Total weight at a given height
    #[returns(cw4::TotalWeightResponse)]
    TotalWeight { at_height: Option<u64> },
    /// Returns the weight of a certain member
    #[returns(cw4::MemberResponse)]
    Member {
        addr: String,
        at_height: Option<u64>,
    },
    /// Shows all registered hooks.
    #[returns(cw_controllers::HooksResponse)]
    Hooks {},
}

Dependencies

~5–7MB
~150K SLoC