Wallet

This document provides a comprehensive overview of the "Wallet" smart contract messages and its sdk. The contract acts primarily as a proxy, forwarding messages received from a list of administrators.

Contract Specification

The Wallet contract is a proxy that works as the actual "wallet" holding funds and forwards messages sent by the administrators. The wallet address is the actual nomos wallet address and the one where funds should be sent.

Instantiate Message

When the contract is instantiated, it requires the following parameters:

  • admins: A list of addresses that will have administrative privileges on the contract.

  • mutable: A boolean value indicating whether the admin list can be altered after instantiation.

  • sender: An optional sender address that, if provided, will be considered the initial requester of the instantiation.

Message definition in rust:

#[cw_serde]
pub struct InstantiateMsg {
    pub admins: Vec<String>,
    pub mutable: bool,
    pub sender: Option<String>,
}

Execute Messages

The contract supports the following execution messages:

  • Execute:

    • Allows the re-dispatch of messages with the contract's address as the sender.

    • This action can be performed only by an admin and is contingent upon the specific implementation logic of the contract.

  • Freeze:

    • Converts a mutable contract into an immutable one, preventing any further changes to the admin list.

    • This action must be initiated by one of the current admins.

  • Update Admins:

    • Updates the list of admin addresses.

    • This is permissible only if the contract is mutable and must be executed by an existing admin.

    • Can only be done by an admin.

Rust messages definition:

#[cw_serde]
pub enum ExecuteMsg<T = Empty>
where
    T: MessageType,
{
    Execute { msgs: Vec<CosmosMsg<T>> },
    Freeze {},
    UpdateAdmins { admins: Vec<String> },
}

Query Messages

Query operations supported by the Wallet contract include:

  • Admin list:

    • Returns a list of current admins and the mutability status of the contract.

  • Can execute:

    • Checks if a given message could be successfully executed by the contract if sent by the specified sender.

    • This query helps in validating permissions before attempting an execution.

Rust message definitions:

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg<T = Empty>
where
    T: Clone + fmt::Debug + PartialEq + JsonSchema,
{
    #[returns(AdminListResponse)]
    AdminList {},
    #[returns(cw1::CanExecuteResponse)]
    CanExecute { sender: String, msg: CosmosMsg<T> },
}

In SDK

The JavaScript/TypeScript API provides a convenient interface for interacting with the Wallet contract through CosmWasm's CosmWasmClient and SigningCosmWasmClient.

Initialization

import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import {Wallet} from "nomos-v2"

const client:SigningCosmwasmClient = // ...
const wallet = new Wallet(client, "<wallet_address>")

Wallet client

  • Query methods:

    • adminList(): Retrieves the list of admins and mutability status.

    • canExecute({msg, sender}): Checks if the specified message can be executed by the sender.

  • Transaction methods:

    • execute({msgs}, fee, memo, _funds): Executes a batch of messages on behalf of the contract.

    • freeze(fee, memo, _funds): Freezes the contract to prevent further admin modifications.

    • updateAdmins({admins}, fee, memo, _funds): Updates the list of administrators, applicable only if the contract is mutable.

Usage

To interact with the Wallet contract, instantiate a WalletClient or WalletQueryClient with the appropriate CosmWasm client and the contract's address. This setup allows for both querying and executing transactions depending on the permissions and methods available to the user.

import { CosmWasmClient, SigningCosmWasmClient, StdFee } from "@cosmjs/cosmwasm-stargate";

// Example: Creating a client and querying admin list
const client:SigningCosmWasmClient = // ...
const walletQueryClient = new WalletQueryClient(client, "<wallet_address>");
const adminList = await walletQueryClient.adminList();
console.log(adminList);

Last updated