A CosmWasm smart contract that automatically forwards funds of a specified denomination to the community pool.
This contract is designed to act as a fund forwarder that:
- Accepts a specific denomination during instantiation
- Forwards all funds of that denomination to the community pool when the
ForwardFundsexecute message is called - Only forwards the specified denomination, ignoring other tokens in the contract's balance
- Configurable Denomination: The contract accepts any denomination during instantiation
- Community Pool Integration: Uses the distribution module's
FundCommunityPoolmessage - State Management: Stores the configured denomination in contract state
- Query Support: Allows querying the contract's configuration
- Comprehensive Testing: Includes unit tests for all functionality
pub struct InstantiateMsg {
pub denom: String,
}- denom: The denomination that this contract will forward to the community pool
pub enum ExecuteMsg {
ForwardFunds {},
}- ForwardFunds: Forwards all funds of the configured denomination to the community pool
pub enum QueryMsg {
Config {},
}- Config: Returns the contract's configuration including the denomination
pub struct ConfigResponse {
pub denom: String,
}# Example with USDN denomination
osmosisd tx wasm instantiate <code_id> '{"denom": "ibc/0C39BD03B5C57A1753A9B73164705871A9B549F1A5226CFD7E39BE7BF73CF8CF"}' \
--label "fund-forwarder" \
--admin <admin_address> \
--gas auto \
--gas-adjustment 1.3 \
--from <key_name># Send funds to the contract address
osmosisd tx bank send <sender_address> <contract_address> 1000000ibc/0C39BD03B5C57A1753A9B73164705871A9B549F1A5226CFD7E39BE7BF73CF8CF \
--gas auto \
--gas-adjustment 1.3 \
--from <key_name># Execute the forward funds message
osmosisd tx wasm execute <contract_address> '{"forward_funds": {}}' \
--gas auto \
--gas-adjustment 1.3 \
--from <key_name>- Rust 1.70+
- wasm-pack (for building)
- cosmwasm-check (for validation)
# Build the contract
cargo build --target wasm32-unknown-unknown --release# Run all tests
cargo test
# Run tests with output
cargo test -- --nocaptureThe contract includes comprehensive tests covering:
- Proper Instantiation: Verifies contract instantiates correctly with denom
- Forward Funds Success: Tests successful forwarding of funds
- No Balance Handling: Tests behavior when contract has no balance
- Zero Balance Handling: Tests behavior with zero balance
- Other Tokens Ignored: Verifies other tokens don't interfere
- Query Configuration: Tests the query functionality
The contract stores its configuration in the following structure:
pub struct Config {
pub denom: String,
}The contract defines the following error types:
NoFunds: Returned when the contract has no balance of the configured denomination
- Access Control: The
ForwardFundsmessage can be called by anyone - Fund Safety: Only forwards the specified denomination, preserving other tokens
- State Immutability: The denomination cannot be changed after instantiation
- Community Pool: Funds are sent to the community pool which is managed by governance