返回顶部
m

market-configurable-skills市场可配置技能

>

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 0.1.0
安全检测
已通过
243
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

market-configurable-skills

可配置加密价格预测市场 Skill

1. 协议与合约概览

  • - 市场合约:contracts/contracts/GouGouBiMarketConfigurable.sol
  • 工厂合约:contracts/contracts/GouGouBiMarketConfigurableFactory.sol
  • 模式:Polymarket 风格 CPMM YES/NO 预测市场。每一轮都有独立的 YES/NO 结果代币,并使用恒定乘积做市商。
  • 关键特性
- 使用 Uniswap V3 池价格作为预言机,计算时间窗口平均价格。 - 可配置预测 token0/token1 或反向(reverseOrder)。 - 支持原生币或任意 ERC20 作为流动性代币。 - 按计划自动开始新一轮,支持到期处理和异常价格处理(通过事件体现)。

本技能仅描述合约 API 和调用模式。实际部署网络和地址应由产品层提供(例如通过 dApp 配置文件或 OpenClow 工作流参数)。


2. 工厂合约 GouGouBiMarketConfigurableFactory

2.1 核心角色和状态

  • - owner:工厂管理员,管理创建者白名单。
  • marketImplementation:被克隆的实现合约(GouGouBiMarketConfigurable)。
  • isWhitelistedCreator[address]:地址是否被允许调用 createMarket。
  • markets[]:所有已创建市场地址的列表。
  • marketIndex[market]:市场地址的索引(从 1 开始,0 表示非此工厂创建)。
  • marketRecords[index]:创建记录(见下文)。

2.2 MarketRecord 结构(只读)

对于工厂创建的每个市场:

  • - market:市场合约地址
  • creator:创建者地址
  • marketName:市场名称
  • uniswapV3Pool:Uniswap V3 池地址
  • liquidityToken:流动性代币地址,address(0) 表示原生币
  • feeRecipient:费用接收地址
  • feeRate:费率(分母 10000)
  • createdAt:创建时间戳
  • 以下字段与 GouGouBiMarketConfigurable.MarketConfig 对齐(见第 3 节):
- tokenDec - reverseOrder - settlementInterval - expiredSeconds - initialReserve - priceLookbackSeconds - imageUrl - rules - timezone - language - groupUrl - tags - predictionToken - anchorToken - currencyUnit

2.3 管理创建者白名单

solidity
function setCreatorWhitelist(address account, bool allowed) external onlyOwner
function setCreatorWhitelistBatch(address[] calldata accounts, bool allowed) external onlyOwner

  • - 仅工厂 owner 可调用。
  • 必须确保 account != address(0)。

2.4 创建市场:createMarket

solidity
function createMarket(GouGouBiMarketConfigurable.MarketConfig memory _config)
external
returns (address market)

约束条件:

  • - 仅 owner 或 isWhitelistedCreator[msg.sender] == true 的地址可创建:
- require(msg.sender == owner || isWhitelistedCreator[msg.sender], NOT_WHITELISTED);
  • - 内部流程:
1. 使用 Clones.clone(marketImplementation) 创建最小代理。 2. 调用新市场的 initialize(_config, msg.sender) 设置配置和所有者。 3. 将市场地址推入 markets[],填充 marketRecords,并更新 marketIndex。 4. 使用关键配置信息触发 MarketCreated 事件。

只读辅助函数:

solidity
function getMarkets() external view returns (address[] memory)
function marketCount() external view returns (uint256)
function getMarketRecord(uint256 index) external view returns (MarketRecord memory)
function getMarketRecordsPaginated(uint256 offset, uint256 limit) external view returns (MarketRecord[] memory)



3. 市场配置 MarketConfig(创建时传入)

工厂 createMarket 使用的 _config 与市场合约内部的 MarketConfig 结构相同:

solidity
struct MarketConfig {
string marketName;
address uniswapV3Pool;
address liquidityToken; // address(0) 表示原生币
uint8 tokenDec; // 如果 liquidityToken==0,在 initialize 中自动设置为 18
bool reverseOrder; // 价格方向:false=Token0/Token1, true=Token1/Token0
uint256 settlementInterval; // 结算间隔(秒)
uint256 expiredSeconds; // 轮次到期时间,若未在此时间前解决则作废
uint256 initialReserve; // 每轮初始虚拟储备(将乘以 10^decimals)
uint32 priceLookbackSeconds;// 平均价格的回溯窗口
address feeRecipient; // 费用接收地址
uint256 feeRate; // 费用分子,分母 10000
string imageUrl;
string rules;
string timezone;
string language;
string groupUrl;
string[] tags;
address predictionToken; // 被预测价格的代币
address anchorToken; // 报价/锚定代币,例如 USDT, BNB
string currencyUnit; // 显示单位,例如 USD, BNB, DOGE
}

关键约束(在 initialize 中验证):

  • - marketName 不能为空:bytes(config.marketName).length > 0
  • uniswapV3Pool != address(0)
  • settlementInterval > 0
  • expiredSeconds > 0
  • 0 < initialReserve <= 1000000000
  • feeRate <= FEEDENOMINATOR (10000)
  • 如果 feeRate > 0,则 feeRecipient != address(0);否则默认为 owner。
  • 如果 liquidityToken == address(0):tokenDec 自动设置为 18。
  • 如果 liquidityToken != address(0):tokenDec = IERC20(liquidityToken).decimals(),要求 tokenDec <= 18。
  • 如果 priceLookbackSeconds == 0:自动设置为 300 秒。

初始化后,合约立即调用 _startNewRound() 开启第 1 轮。



4. 市场轮次 RoundInfo 和价格结算

4.1 RoundInfo 结构

solidity
struct RoundInfo {
uint8 winning; // 0=未结算, 1=YES 赢, 2=NO 赢, 3=平局/异常
uint256 poolAmount; // 该轮池中的总流动性代币数量
uint256 x; // CPMM x 储备(YES 池)
uint256 y; // CPMM y 储备(NO 池)
address yesToken; // 该轮的 YES 结果代币
address noToken; // 该轮的 NO 结果代币
uint256 startTime; // 轮次开始时间
uint256 endTime; // 预定结算时间
uint256 expiredTime; // 到期时间(如果超过,视为 winning=3)
uint256 startAveragePrice; // 轮次开始时的平均价格
uint256 endAveragePrice; // 轮次结束/结算时的平均价格
}

  • - 通过只读映射 rounds[round] 访问。
  • 当前轮次索引:currentRound。

4.2 价格获取:getAveragePriceFromUniswapV3

solidity
function getAveragePriceFromUniswapV3(uint32 startTime, uint32 endTime)
public
view
returns (uint256 averagePrice)

  • - startTime < endTime,且 endTime <= block.timestamp。
  • 内部使用 Uniswap V3 observe + TickMath 计算区间内的平均价格,以 1e18 精度表示。
  • 如果 reverseOrder == true,则取价格的倒数(仍以 1e18 精度表示)。

4.3 结算和轮次转换

  • - _checkAndExecuteSettlement():在每次交易/赎回/解决前调用,用于:
- 如果 block.timestamp > expiredTime:设置 winning = 3,endAveragePrice = 0,触发 Auto

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 market-configurable-skills-1776197360 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 market-configurable-skills-1776197360 技能

通过命令行安装

skillhub install market-configurable-skills-1776197360

下载

⬇ 下载 market-configurable-skills v0.1.0(免费)

文件大小: 13.15 KB | 发布时间: 2026-4-15 11:54

v0.1.0 最新 2026-4-15 11:54
Initial release of the market-configurable-skills package.

- Provides contract call guides and best practices for GouGouBiMarketConfigurable and GouGouBiMarketConfigurableFactory.
- Documents all key factory operations, including creator whitelisting, market creation, and market record retrieval.
- Details the full MarketConfig structure, covering all configurable parameters and constraints.
- Explains core market round structures, Uniswap V3 price oracle integration, and settlement flow.
- Intended for use in contract calls from scripts, dApps, or workflows (e.g., OpenClow) for creating and interacting with configurable crypto price prediction markets.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部