defi
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDeFi Skill
DeFi 技能
Provides DeFi operations across two protocols:
- ALEX DEX — Automated Market Maker (AMM) on Stacks for token swaps. Uses the alex-sdk for routing and price discovery. Mainnet-only.
- Zest Protocol — Lending and borrowing protocol on Stacks. Supply assets to earn interest, borrow against collateral. Mainnet-only.
Write operations (swap, supply, withdraw, borrow, repay, claim-rewards) require an unlocked wallet (use first). Read operations (get-swap-quote, get-pool-info, list-pools, list-assets, get-position) also require an unlocked wallet for routing context.
bun run wallet/wallet.ts unlock提供跨两个协议的DeFi操作:
- ALEX DEX — 基于Stacks的自动化做市商(AMM),用于代币兑换。使用alex-sdk进行路由与价格发现。仅支持主网。
- Zest Protocol — 基于Stacks的借贷协议。存入资产赚取利息,可抵押借入资产。仅支持主网。
写入类操作(兑换、存入、提取、借入、偿还、领取奖励)需要解锁钱包(请先执行)。读取类操作(获取兑换报价、获取池信息、列出流动性池、列出资产、获取持仓)也需要解锁钱包以获取路由上下文。
bun run wallet/wallet.ts unlockUsage
使用方法
bun run defi/defi.ts <subcommand> [options]bun run defi/defi.ts <子命令> [选项]Subcommands
子命令
alex-get-swap-quote
alex-get-swap-quote
Get a swap quote from ALEX DEX. Returns the expected output amount for swapping tokenX to tokenY.
bun run defi/defi.ts alex-get-swap-quote --token-x <contractId> --token-y <contractId> --amount-in <units>Options:
- (required) — Input token: contract ID (e.g.,
--token-x) or symbol (SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx-v2,STX)ALEX - (required) — Output token: contract ID or symbol
--token-y - (required) — Amount of tokenX to swap (in smallest units)
--amount-in
Output:
json
{
"network": "mainnet",
"quote": {
"tokenIn": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx-v2",
"tokenOut": "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex",
"amountIn": "1000000",
"expectedAmountOut": "52341",
"route": ["STX", "ALEX"]
}
}从ALEX DEX获取兑换报价。返回将tokenX兑换为tokenY的预计输出数量。
bun run defi/defi.ts alex-get-swap-quote --token-x <contractId> --token-y <contractId> --amount-in <units>选项:
- (必填)—— 输入代币:合约ID(例如:
--token-x)或代币符号(SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx-v2、STX)ALEX - (必填)—— 输出代币:合约ID或代币符号
--token-y - (必填)—— 要兑换的tokenX数量(以最小单位计)
--amount-in
输出:
json
{
"network": "mainnet",
"quote": {
"tokenIn": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx-v2",
"tokenOut": "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex",
"amountIn": "1000000",
"expectedAmountOut": "52341",
"route": ["STX", "ALEX"]
}
}alex-swap
alex-swap
Execute a token swap on ALEX DEX. Requires an unlocked wallet.
bun run defi/defi.ts alex-swap --token-x <contractId> --token-y <contractId> --amount-in <units> [--min-amount-out <units>]Options:
- (required) — Input token: contract ID or symbol
--token-x - (required) — Output token: contract ID or symbol
--token-y - (required) — Amount of tokenX to swap (in smallest units)
--amount-in - (optional) — Minimum acceptable output amount for slippage protection (default: 0)
--min-amount-out
Output:
json
{
"success": true,
"txid": "abc123...",
"swap": {
"tokenIn": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx-v2",
"tokenOut": "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex",
"amountIn": "1000000",
"minAmountOut": "0"
},
"network": "mainnet",
"explorerUrl": "https://explorer.hiro.so/txid/abc123...?chain=mainnet"
}在ALEX DEX执行代币兑换。需要解锁钱包。
bun run defi/defi.ts alex-swap --token-x <contractId> --token-y <contractId> --amount-in <units> [--min-amount-out <units>]选项:
- (必填)—— 输入代币:合约ID或代币符号
--token-x - (必填)—— 输出代币:合约ID或代币符号
--token-y - (必填)—— 要兑换的tokenX数量(以最小单位计)
--amount-in - (可选)—— 滑点保护的最低可接受输出数量(默认值:0)
--min-amount-out
输出:
json
{
"success": true,
"txid": "abc123...",
"swap": {
"tokenIn": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx-v2",
"tokenOut": "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex",
"amountIn": "1000000",
"minAmountOut": "0"
},
"network": "mainnet",
"explorerUrl": "https://explorer.hiro.so/txid/abc123...?chain=mainnet"
}alex-get-pool-info
alex-get-pool-info
Get liquidity pool information from ALEX DEX. Returns reserve balances and pool details for a token pair.
bun run defi/defi.ts alex-get-pool-info --token-x <contractId> --token-y <contractId>Options:
- (required) — First token contract ID or symbol
--token-x - (required) — Second token contract ID or symbol
--token-y
Output:
json
{
"network": "mainnet",
"pool": {
"poolId": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx-v2-SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex",
"tokenX": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx-v2",
"tokenY": "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex",
"reserveX": "5000000000",
"reserveY": "12000000000",
"totalShares": "8000000000"
}
}从ALEX DEX获取流动性池信息。返回代币对的储备余额与池详情。
bun run defi/defi.ts alex-get-pool-info --token-x <contractId> --token-y <contractId>选项:
- (必填)—— 第一个代币的合约ID或代币符号
--token-x - (必填)—— 第二个代币的合约ID或代币符号
--token-y
输出:
json
{
"network": "mainnet",
"pool": {
"poolId": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx-v2-SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex",
"tokenX": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx-v2",
"tokenY": "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex",
"reserveX": "5000000000",
"reserveY": "12000000000",
"totalShares": "8000000000"
}
}alex-list-pools
alex-list-pools
List all available trading pools on ALEX DEX.
bun run defi/defi.ts alex-list-pools [--limit <n>]Options:
- (optional) — Maximum number of pools to return (default: 50)
--limit
Output:
json
{
"network": "mainnet",
"poolCount": 3,
"pools": [
{
"id": 1,
"pair": "wstx-v2/alex",
"tokenX": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx-v2",
"tokenY": "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex",
"factor": "100000000"
}
],
"usage": "Use the tokenX and tokenY contract IDs with alex-get-swap-quote or alex-swap"
}列出ALEX DEX上所有可用的交易池。
bun run defi/defi.ts alex-list-pools [--limit <n>]选项:
- (可选)—— 返回的最大池数量(默认值:50)
--limit
输出:
json
{
"network": "mainnet",
"poolCount": 3,
"pools": [
{
"id": 1,
"pair": "wstx-v2/alex",
"tokenX": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx-v2",
"tokenY": "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex",
"factor": "100000000"
}
],
"usage": "Use the tokenX and tokenY contract IDs with alex-get-swap-quote or alex-swap"
}zest-list-assets
zest-list-assets
List all supported assets on Zest Protocol.
bun run defi/defi.ts zest-list-assetsOutput:
json
{
"network": "mainnet",
"assetCount": 3,
"assets": [
{
"symbol": "sBTC",
"name": "Stacked Bitcoin",
"contractId": "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token"
},
{
"symbol": "stSTX",
"name": "Stacked STX",
"contractId": "SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token"
}
],
"usage": "Use the symbol (e.g., 'stSTX') or full contract ID in other zest-* commands"
}列出Zest Protocol支持的所有资产。
bun run defi/defi.ts zest-list-assets输出:
json
{
"network": "mainnet",
"assetCount": 3,
"assets": [
{
"symbol": "sBTC",
"name": "Stacked Bitcoin",
"contractId": "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token"
},
{
"symbol": "stSTX",
"name": "Stacked STX",
"contractId": "SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token"
}
],
"usage": "Use the symbol (e.g., 'stSTX') or full contract ID in other zest-* commands"
}zest-get-position
zest-get-position
Get a user's lending position on Zest Protocol.
bun run defi/defi.ts zest-get-position --asset <symbolOrContractId> [--address <addr>]Options:
- (required) — Asset symbol (e.g.,
--asset,stSTX) or full contract IDaeUSDC - (optional) — User address (uses active wallet if omitted)
--address
Output:
json
{
"network": "mainnet",
"address": "SP2...",
"position": {
"asset": "SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token",
"supplied": "5000000",
"borrowed": "0"
}
}获取用户在Zest Protocol上的借贷持仓。
bun run defi/defi.ts zest-get-position --asset <symbolOrContractId> [--address <addr>]选项:
- (必填)—— 资产符号(例如:
--asset、stSTX)或完整合约IDaeUSDC - (可选)—— 用户地址(若省略则使用当前活跃钱包)
--address
输出:
json
{
"network": "mainnet",
"address": "SP2...",
"position": {
"asset": "SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token",
"supplied": "5000000",
"borrowed": "0"
}
}zest-supply
zest-supply
Supply assets to the Zest Protocol lending pool to earn interest. Requires an unlocked wallet.
bun run defi/defi.ts zest-supply --asset <symbolOrContractId> --amount <units> [--on-behalf-of <addr>]Options:
- (required) — Asset symbol or full contract ID
--asset - (required) — Amount to supply (in smallest units)
--amount - (optional) — Supply on behalf of another address
--on-behalf-of
Output:
json
{
"success": true,
"txid": "abc123...",
"action": "supply",
"asset": "SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token",
"amount": "5000000",
"onBehalfOf": "SP2...",
"network": "mainnet",
"explorerUrl": "https://explorer.hiro.so/txid/abc123...?chain=mainnet"
}将资产存入Zest Protocol借贷池以赚取利息。需要解锁钱包。
bun run defi/defi.ts zest-supply --asset <symbolOrContractId> --amount <units> [--on-behalf-of <addr>]选项:
- (必填)—— 资产符号或完整合约ID
--asset - (必填)—— 要存入的数量(以最小单位计)
--amount - (可选)—— 代其他地址存入
--on-behalf-of
输出:
json
{
"success": true,
"txid": "abc123...",
"action": "supply",
"asset": "SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token",
"amount": "5000000",
"onBehalfOf": "SP2...",
"network": "mainnet",
"explorerUrl": "https://explorer.hiro.so/txid/abc123...?chain=mainnet"
}zest-withdraw
zest-withdraw
Withdraw assets from the Zest Protocol lending pool. Requires an unlocked wallet.
bun run defi/defi.ts zest-withdraw --asset <symbolOrContractId> --amount <units>Options:
- (required) — Asset symbol or full contract ID
--asset - (required) — Amount to withdraw (in smallest units)
--amount
Output:
json
{
"success": true,
"txid": "abc123...",
"action": "withdraw",
"asset": "SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token",
"amount": "5000000",
"network": "mainnet",
"explorerUrl": "https://explorer.hiro.so/txid/abc123...?chain=mainnet"
}从Zest Protocol借贷池提取资产。需要解锁钱包。
bun run defi/defi.ts zest-withdraw --asset <symbolOrContractId> --amount <units>选项:
- (必填)—— 资产符号或完整合约ID
--asset - (必填)—— 要提取的数量(以最小单位计)
--amount
输出:
json
{
"success": true,
"txid": "abc123...",
"action": "withdraw",
"asset": "SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token",
"amount": "5000000",
"network": "mainnet",
"explorerUrl": "https://explorer.hiro.so/txid/abc123...?chain=mainnet"
}zest-borrow
zest-borrow
Borrow assets from Zest Protocol against supplied collateral. Requires an unlocked wallet.
bun run defi/defi.ts zest-borrow --asset <symbolOrContractId> --amount <units>Options:
- (required) — Asset symbol or full contract ID
--asset - (required) — Amount to borrow (in smallest units)
--amount
Output:
json
{
"success": true,
"txid": "abc123...",
"action": "borrow",
"asset": "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token",
"amount": "100000",
"network": "mainnet",
"explorerUrl": "https://explorer.hiro.so/txid/abc123...?chain=mainnet"
}以存入的资产为抵押,从Zest Protocol借入资产。需要解锁钱包。
bun run defi/defi.ts zest-borrow --asset <symbolOrContractId> --amount <units>选项:
- (必填)—— 资产符号或完整合约ID
--asset - (必填)—— 要借入的数量(以最小单位计)
--amount
输出:
json
{
"success": true,
"txid": "abc123...",
"action": "borrow",
"asset": "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token",
"amount": "100000",
"network": "mainnet",
"explorerUrl": "https://explorer.hiro.so/txid/abc123...?chain=mainnet"
}zest-repay
zest-repay
Repay borrowed assets to Zest Protocol. Requires an unlocked wallet.
bun run defi/defi.ts zest-repay --asset <symbolOrContractId> --amount <units> [--on-behalf-of <addr>]Options:
- (required) — Asset symbol or full contract ID
--asset - (required) — Amount to repay (in smallest units)
--amount - (optional) — Repay on behalf of another address
--on-behalf-of
Output:
json
{
"success": true,
"txid": "abc123...",
"action": "repay",
"asset": "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token",
"amount": "100000",
"onBehalfOf": "SP2...",
"network": "mainnet",
"explorerUrl": "https://explorer.hiro.so/txid/abc123...?chain=mainnet"
}向Zest Protocol偿还借入的资产。需要解锁钱包。
bun run defi/defi.ts zest-repay --asset <symbolOrContractId> --amount <units> [--on-behalf-of <addr>]选项:
- (必填)—— 资产符号或完整合约ID
--asset - (必填)—— 要偿还的数量(以最小单位计)
--amount - (可选)—— 代其他地址偿还
--on-behalf-of
输出:
json
{
"success": true,
"txid": "abc123...",
"action": "repay",
"asset": "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token",
"amount": "100000",
"onBehalfOf": "SP2...",
"network": "mainnet",
"explorerUrl": "https://explorer.hiro.so/txid/abc123...?chain=mainnet"
}zest-claim-rewards
zest-claim-rewards
Claim accumulated rewards from the Zest Protocol incentives program. sBTC suppliers earn wSTX rewards. Requires an unlocked wallet.
bun run defi/defi.ts zest-claim-rewards [--asset <symbolOrContractId>]Options:
- (optional) — Asset you supplied to earn rewards (default:
--asset)sBTC
Output:
json
{
"success": true,
"txid": "abc123...",
"action": "claim_rewards",
"asset": "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token",
"rewardAsset": "wSTX",
"network": "mainnet",
"explorerUrl": "https://explorer.hiro.so/txid/abc123...?chain=mainnet",
"note": "Rewards will be sent to your wallet once the transaction confirms."
}从Zest Protocol激励计划中领取累计奖励。存入sBTC的用户可赚取wSTX奖励。需要解锁钱包。
bun run defi/defi.ts zest-claim-rewards [--asset <symbolOrContractId>]选项:
- (可选)—— 用于赚取奖励的存入资产(默认值:
--asset)sBTC
输出:
json
{
"success": true,
"txid": "abc123...",
"action": "claim_rewards",
"asset": "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token",
"rewardAsset": "wSTX",
"network": "mainnet",
"explorerUrl": "https://explorer.hiro.so/txid/abc123...?chain=mainnet",
"note": "Rewards will be sent to your wallet once the transaction confirms."
}Notes
注意事项
- ALEX DEX and Zest Protocol are mainnet-only. Calls on testnet will return an error.
- For ALEX swap quotes, you can use token symbols (,
STX) or full contract IDs. UseALEXto discover available pairs.alex-list-pools - For Zest operations, you can use asset symbols (,
stSTX,aeUSDC) or full contract IDs. UsesBTCto discover supported assets.zest-list-assets - Wallet operations require an unlocked wallet (use first).
bun run wallet/wallet.ts unlock - Borrow operations require sufficient collateral in the protocol. Ensure you have supplied assets before borrowing.
- ALEX DEX与Zest Protocol仅支持主网。在测试网调用会返回错误。
- 对于ALEX兑换报价,你可以使用代币符号(、
STX)或完整合约ID。使用ALEX查看可用交易对。alex-list-pools - 对于Zest操作,你可以使用资产符号(、
stSTX、aeUSDC)或完整合约ID。使用sBTC查看支持的资产。zest-list-assets - 钱包操作需要解锁钱包(请先执行)。
bun run wallet/wallet.ts unlock - 借入操作需要在协议中有足够的抵押品。请确保在借入前已存入资产。