2 个版本
0.0.4 | 2023 年 8 月 3 日 |
---|---|
0.0.3 | 2023 年 7 月 31 日 |
#5 在 #tokenfactory
每月 21 次下载
25KB
443 行
TokenFactory Core (中间件)
这是一个合约,您将 TokenFactory 模块中您的代币面额的管理员权限交由该合约。一旦该合约拥有这些权限,它就允许您/您的 DAO 控制的其他合约为您业务逻辑的需求(通过 WasmMsg)铸造代币。
这使得它更加灵活,因为多个合约可以为合约管理员“铸造”代币 :D
示例用例
$RAC 有插槽和骰子合约。如果他们想要为每次游戏为您铸造 1 RAC,那么插槽和骰子都需要是 token-factory 代币的管理员才能铸造。通过这个核心合约,一个合约是管理员,然后 DAO 可以将骰子和插槽地址列入白名单,以便代表其铸造代币。
这样铸造 $RAC,骰子合约将向核心合约发送一个 WasmMsg 铸造请求,然后向用户提供该代币。
Rust 依赖
将以下内容添加到您的 Cargo.toml
依赖项中用于合约。然后查看本文件的 Mint 部分,了解如何实现。
[dependencies]
juno-tokenfactory-types = { git = "https://github.com/CosmosContracts/tokenfactory-contracts" }
或从 crates.io - https://crates.io/crates/juno-tokenfactory-core
您可以在 示例合约 中查看如何使用此功能,或者查看 e2e 测试 以了解完整的 bash 示例。
链设置
主网存储代码:待定
# for uni-6 TESTNET
# update [key] here to be your local wallet's key or your wallet's address
FLAGS="--gas-prices 0.003ujuno --gas auto --gas-adjustment 1.3 --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 --output json --from [key]"
# create a tokenfactory denomination via the CLI.
junod tx tokenfactory create-denom abcde $FLAGS
# factory/juno1......./abcde is your new denom
# upload this contract (skip if you use the mainnet code)
# junod tx wasm store artifacts/juno_tokenfactory_core.wasm $FLAGS
# Initialize this contract
# You may want to set this as a normal admin initially before changing its admin to a DAO
junod tx wasm instantiate "###" {"allowed_mint_addresses":[],"denoms":["factory/juno1./abcde"]} --label "tf-middlware" --admin [key] $FLAGS
# Get the middleware contract address here
# Transfer ownership of the token to the contract
junod tx tokenfactory change-admin factory/juno1./abcde juno1middlewarecontract $FLAGS
# Ensure the juno1middlewarecontract now has the admin role
junod q tokenfactory denom-authority-metadata factory/juno1./abcde
如何合约铸造
然后,您可以使用以下示例通过另一个合约铸造代币
// msg.rs - mint on behalf of the core_factory_address
#[cw_serde]
pub enum ExecuteMsg {
MintTokens {
// You could save this in state.rs on initialize.
core_tf_middleware_contract: String,
denoms: Vec<Coin>,
to_address: String,
},
}
// contract.rs - execute
// Ensure you added the tokenfactory-types dependency
use juno::juno_tokenfactory_types::msg::ExecuteMsg::Mint;
ExecuteMsg::MintTokens {
core_tf_middleware_contract,
denoms,
to_address,
} => {
let payload = Mint {
address: to_address,
denom: denoms,
};
let wasm_msg = WasmMsg::Execute {
contract_addr: core_tf_middleware_contract.to_string(),
msg: to_binary(&payload)?,
funds: vec![],
};
Ok(Response::new()
.add_attribute("method", "execute_mint_tokens_from_other_contract")
.add_message(wasm_msg))
}
依赖项
~4–6MB
~125K SLoC