Skip to content

Instantly share code, notes, and snippets.

@larry0x
Last active August 25, 2023 23:26
Show Gist options
  • Save larry0x/8fd1c64bd00b64a12e8114a30ccf79d9 to your computer and use it in GitHub Desktop.
Save larry0x/8fd1c64bd00b64a12e8114a30ccf79d9 to your computer and use it in GitHub Desktop.
CW-SDK bank contract

CW-SDK's bank contract will manage both fungible and nonfungible tokens.

  • Each fungible token is identified by a denom
  • Each nonfungible token is identified by a tuple (denom, sequence) where sequence is a u64; the 1st token in the collection gets a sequence of 0, the 2nd gets 1, so on

An NFT collection cannot share the same denom with a fungible token.

struct Coin {
    pub denom:  String,
    pub amount: Uint128,
}

struct Nft {
    pub denom:    String,
    pub sequence: u64,
}

The bank contract stores user coin and NFT holdings in the following mapping:

// fungible token balances
// (user_addr, denom) => balance
const COIN_BALANCES: Map<(&Addr, &str), Uint128>;

// nonfungible token balances
// (user_addr, denom, sequence) => Empty
const NFT_BALANCES: Map<(&Addr, &str, u64), Empty>;

The user can send any number of coins and NFTs in a single action by calling the bank contract with the following message:

enum BankExecuteMsg {
    Send {
        recipient: String,
        coins:     Vec<Coin>,
        nfts:      Vec<Nft>,
    },
}

The WasmMsg::{Instantiate, Execute} will be extended to allow transferring NFTs:

enum WasmMsg {
    Instantiate {
        code_hash: Binary,
        msg:       Binary,
        funds:     Vec<Coin>,
        nfts:      Vec<Nft>, // new!
        admin:     Option<String>,
        salt:      Option<Binary>,
    },
    Execute {
        contract: String,
        msg:      Binary,
        funds:    Vec<Coin>,
        nfts:     Vec<Nft>, // new!
    },
}

MessageInfo will be extended to include NFTs as well:

struct MessageInfo {
    pub sender: Addr,
    pub funds:  Vec<Coin>,
    pub nfts:   Vec<Nft>, // new!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment