An AI Coding Skill for on-chain operations on DERIW DEX, supporting open/close positions, limit orders, fund pools, cross-chain deposits/withdrawals, and more. The underlying scripts are based on ethers.js v6 and support both production network and devnet (DEV=true).
Supports Claude Code, OpenClaw, Gemini CLI, and Codex.
Prerequisite for all platforms: Node.js 18+ must be installed for running on-chain scripts.
# Global (available across all projects)
cd ~/.claude/commands
git clone https://github.com/deriwfi/deriw-ai deriw
cd deriw && npm install# Project-level (current project only)
cd <your-project>/.claude/commands
git clone https://github.com/deriwfi/deriw-ai deriw
cd deriw && npm installInvoke via slash command:
/deriw query the current BTC price
# Global (available across all agents)
cd ~/.openclaw/skills
git clone https://github.com/deriwfi/deriw-ai deriw
cd deriw && npm install# Project-level (current workspace only)
cd <your-workspace>/skills
git clone https://github.com/deriwfi/deriw-ai deriw
cd deriw && npm installOpenClaw auto-discovers skills on next session. Describe your intent naturally or use the slash command:
/deriw query the current BTC price
To add extra skill directories, configure skills.load.extraDirs in ~/.openclaw/openclaw.json:
{
"skills": {
"load": {
"extraDirs": ["/path/to/custom/skills"]
}
}
}# Global (available across all projects)
mkdir -p ~/.gemini/skills
cd ~/.gemini/skills
git clone https://github.com/deriwfi/deriw-ai deriw
cd deriw && npm install# Project-level (current project only)
mkdir -p .gemini/skills
cd .gemini/skills
git clone https://github.com/deriwfi/deriw-ai deriw
cd deriw && npm installGemini CLI is model-invoked — describe your intent and the model automatically activates the skill via activate_skill. No slash command needed:
Deposit 100 USDT into the DERIW fund pool
# Global — Codex scans ~/.agents/skills/ at startup
mkdir -p ~/.agents/skills
cd ~/.agents/skills
git clone https://github.com/deriwfi/deriw-ai deriw
cd deriw && npm installCodex auto-discovers skills in ~/.agents/skills/ at startup. Describe your intent naturally or mention the skill by name:
Open a BTC long with 100 USDT margin on DERIW
To uninstall, remove the directory:
rm -rf ~/.agents/skills/deriwDescribe your intent in natural language. Each platform has a slightly different invocation method:
| Platform | Invocation | Example |
|---|---|---|
| Claude Code | /deriw <description> |
/deriw open BTC long |
| OpenClaw | /deriw <description> |
/deriw query ETH price |
| Gemini CLI | Describe naturally (model-invoked) | Withdraw 50 USDT to Arbitrum |
| Codex | Describe naturally (model-invoked) | Close my BTC position on DERIW |
All on-chain scripts read the private key via the PRIVATE_KEY environment variable. Export it before running:
export PRIVATE_KEY=0xyour_private_keyFor devnet, additionally set DEV=true:
export DEV=true/deriw start an Edge Hour challenge with template 12
/deriw open BTC long in Edge Hour challenge 35329
/deriw close my Edge Hour BTC position
/deriw claim Edge Hour reward for challenge 35329
/deriw deposit 100 USDT into Edge Hour LP vault
Corresponding scripts:
# Query state (templates, vault, user challenge)
DEV=true node scripts/edge_hour/query-state.js <account>
# Start challenge (templateId from query-state; ticketFee must be multiple of 5 USDT)
DEV=true PRIVATE_KEY=xxx node scripts/edge_hour/start-challenge.js <templateId> <ticketFee_usdt>
# Open virtual position (no token transfer)
DEV=true PRIVATE_KEY=xxx node scripts/edge_hour/open-position.js <challengeId> <indexToken> <sizeDelta_usdt> <collateral_usdt> <isLong>
# Close virtual position
DEV=true PRIVATE_KEY=xxx node scripts/edge_hour/close-position.js <challengeId> <indexToken> <isLong>
# Claim reward (challenge must be status=2 Passed)
DEV=true PRIVATE_KEY=xxx node scripts/edge_hour/claim-reward.js <challengeId>
# LP vault deposit (whitelist required — contact vault owner)
DEV=true PRIVATE_KEY=xxx node scripts/edge_hour/lpvault-deposit.js <amount_usdt>
# LP vault withdraw
DEV=true PRIVATE_KEY=xxx node scripts/edge_hour/lpvault-withdraw.js <amount_usdt | all>
# Batch API query
DEV=true node scripts/edge_hour/query-api.js <account> [challengeId]Key precision: all amounts (ticketFee, sizeDelta, collateral, balance) use 1e6 (USDT unit). Prices from PriceOracle.getPrice() use 1e18.
Room mode = a host-created isolated liquidity pool ("channel pool"). Every endpoint is
keyed by account = the host/creator address (NOT a trader wallet). Room has no dedicated
contracts — it reuses Phase / Slippage / MemeFactory / MemeData / Vault.
/deriw apply to become a room host (Principal mode)
/deriw show room detail for host 0xHostAddress
/deriw list traders and open positions in the room
Corresponding scripts:
# Apply to become a host / (re)open a room — the ONLY room write flow.
# Produces personal_sign("Apply to become a host") and POSTs to /client/room/pre-create.
# capacityBaseMode: 1 = Principal, 2 = Equity
DEV=true PRIVATE_KEY=xxx node scripts/room/pre-create.js <capacityBaseMode>
# On-chain state reader (reuses Phase / Slippage / MemeFactory / Vault reads)
DEV=true node scripts/room/query-state.js <hostAccount> [indexToken] [isLong]
# Batch API query (detail, traders, positions, close history, LP changes, fee/TVL, pool status, coins)
DEV=true node scripts/room/query-api.js <hostAccount>Note: account in all room scripts/endpoints is the host address, and it locates the
host's single active room. See references/api.md §3.13 for the /client/room/* endpoints.
/deriw query BTC long position for 0xAbc...
/deriw query current ETH price
Corresponding script:
DEV=true node scripts/query-position.js <account> <indexToken> <isLong>/deriw open BTC 10x long with 100 USDT margin, position size 1000 USD
/deriw close my BTC long position
Corresponding scripts:
# Open
PRIVATE_KEY=xxx node scripts/create-market-open.js <indexToken> <amountIn_usdt> <sizeDelta_usd> <isLong>
# Close
PRIVATE_KEY=xxx node scripts/create-market-close.js <indexToken> <sizeDelta_usd> <isLong>/deriw open BTC long 1000 USD when price drops to 80000
/deriw place a BTC take-profit order at 100000
Corresponding scripts:
# Limit open
PRIVATE_KEY=xxx node scripts/create-limit-open.js <indexToken> <amountIn_usdt> <sizeDelta_usd> <isLong> <triggerPrice_usd> <triggerAbove>
# Limit close
PRIVATE_KEY=xxx node scripts/create-limit-close.js <indexToken> <sizeDelta_usd> <isLong> <triggerPrice_usd> <triggerAbove>/deriw deposit 100 USDT into fund pool
Corresponding script (pid obtained from API or contract currPeriodID):
DEV=true PRIVATE_KEY=xxx node scripts/fund-deposit.js <poolAddress> <pid> <amount_usdt>/deriw deposit 100 USDT from Arbitrum to DERIW Chain
Corresponding script (must run on Arbitrum network):
# Production
PRIVATE_KEY=xxx node scripts/crosschain-deposit.js <amount_usdt>
# Devnet (Arbitrum Sepolia)
DEV=true PRIVATE_KEY=xxx node scripts/crosschain-deposit.js <amount_usdt>/deriw withdraw 50 USDT to Arbitrum
Corresponding script (runs on DERIW Chain):
# Production
PRIVATE_KEY=xxx node scripts/crosschain-withdraw.js <amount_usdt>
# Devnet
DEV=true PRIVATE_KEY=xxx node scripts/crosschain-withdraw.js <amount_usdt>| Network | RPC | Chain ID |
|---|---|---|
| DERIW Chain (Production) | https://rpc.deriw.com |
2885 |
| DERIW Dev Chain | https://rpc.dev.deriw.com |
18417507517 |
| Arbitrum (Production) | https://arb1.arbitrum.io/rpc |
42161 |
| Arbitrum Sepolia (Devnet) | https://rpc-arbitrum-sepolia.deriw.com |
421614 |
references/addresses.md— Full contract addresses + token addressesreferences/contracts.md— Contract method descriptionsreferences/api.md— HTTP API documentationscripts/— Ready-to-run ethers.js v6 scripts (8 total)scripts/edge_hour/— Edge Hour specific scripts (8 total)scripts/room/— Room mode scripts (pre-create, query-state, query-api)assets/— Contract ABI JSON filesassets/edge-hour/— Edge Hour ABI files (ChallengeManager, LPVault, PriceOracle)assets/room/— Room mode reused ABIs (Phase, Slippage, MemeFactory, MemeData, Vault, VaultUtils)
- Private key security:
PRIVATE_KEYis only passed via environment variable, never write it to any file - Devnet: Add
DEV=trueto switch to testnet; devnet hasgasPrice=0, no ETH required - Cross-chain arrival time: Deposits 5-15 minutes, withdrawals 15-60 minutes (Arbitrum confirmation)
- Edge Hour LPVault:
deposit()requires whitelist by vault owner — contact team to be whitelisted - Edge Hour virtual trading:
increasePosition/closePositiondo NOT move real tokens; all balances are tracked on-chain as virtual equity