Credex Protocol Skill
Interact with the Credex Protocol—a decentralized credit system for AI agents on the Arc Network.
Usage
Base Directory: {baseDir} (the directory containing this SKILL.md)
Run all commands from the project root:
CODEBLOCK0
Output Format: All scripts return JSON for machine readability. Parse the output to extract fields like creditLimit, txHash, debt, etc.
Environment Variables
Required (Must Be Set)
| Variable | Description |
|---|
| INLINECODE4 | Private key for signing transactions. Without this, all commands fail. |
| INLINECODE5 |
Arc Network RPC. Default:
https://rpc.testnet.arc.network |
Optional
| Variable | Description | Default |
|---|
| INLINECODE7 | Pool contract address | INLINECODE8 |
| INLINECODE9 |
Credex agent server URL |
http://localhost:10003 |
Pre-Flight Check: Before running any command, verify WALLET_PRIVATE_KEY is set. If missing, prompt the user.
Contract Addresses (Arc Testnet)
| Contract | Address |
|---|
| INLINECODE12 | INLINECODE13 |
| INLINECODE14 (Arc) |
0x3600000000000000000000000000000000000000 |
|
USDC (Base Sepolia) |
0x036CbD53842c5426634e7929541eC2318f3dCF7e |
Client Commands (Borrower)
Script: scripts/client.ts
Run as: npx ts-node scripts/client.ts <command> [args]
status
Check credit status for an agent.
Usage:
CODEBLOCK1
Args:
- -
address (optional): Wallet address. Defaults to WALLET_PRIVATE_KEY address.
Returns: JSON
CODEBLOCK2
Action: Use availableCredit to check if sufficient funds before calling borrow.
borrow
Borrow USDC from the pool.
Usage:
CODEBLOCK3
Args:
- -
amount (required): USDC amount as decimal string (e.g., "5.0").
Returns: JSON
CODEBLOCK4
Fails if: amount > availableCredit. Check status first.
repay
Repay debt to the pool.
Usage:
CODEBLOCK5
Args:
- -
amount: Specific USDC amount to repay (e.g., "5.0"). - INLINECODE33 : Calculates total debt + 1% buffer and repays fully. The contract caps at actual debt owed.
Returns: JSON
CODEBLOCK6
Note: Repayments pay interest first, then principal. Each successful repayment increases credit limit by 10%.
bridge
Bridge USDC between Arc Testnet and Base Sepolia.
Usage:
CODEBLOCK7
Args:
- -
amount: USDC amount (e.g., "10.0"). - INLINECODE37 : Source chain (
arc or base). - INLINECODE40 : Destination chain (
arc or base).
Returns: JSON
CODEBLOCK8
Fails if: from === to. Chains must be different.
balance
Check wallet balance on both chains.
Usage:
CODEBLOCK9
Returns: JSON
CODEBLOCK10
LP Commands (Liquidity Provider)
Script: scripts/lp.ts
Run as: npx ts-node scripts/lp.ts <command> [args]
pool-status
Check overall pool health and metrics.
Usage:
CODEBLOCK11
Returns: JSON
CODEBLOCK12
deposit
Deposit USDC to receive LP shares.
Usage:
CODEBLOCK13
Args:
- -
amount: USDC to deposit (e.g., "100.0").
Returns: JSON
CODEBLOCK14
withdraw
Burn LP shares to withdraw USDC.
Usage:
CODEBLOCK15
Args:
- -
shares: Number of shares to burn (e.g., "50.0"). - INLINECODE54 : Withdraw maximum possible based on available liquidity.
Returns: JSON
CODEBLOCK16
Note: Withdrawal may be capped if liquidity is fully utilized (all USDC lent out).
lp-balance
Check LP position for an address.
Usage:
CODEBLOCK17
Returns: JSON
CODEBLOCK18
Protocol Mechanics
Interest Accrual
- - Rate: 0.1% per interval (10 basis points)
- Interval: 1 minute (testnet accelerated)
- Formula: INLINECODE56
Credit Limit Growth
After each repayment:
CODEBLOCK19
Maximum: 10,000 USDC.
Available Credit
CODEBLOCK20
Interest does NOT reduce borrowing power—only principal.
Share Price (LP)
CODEBLOCK21
Where totalAssets = liquidity + outstandingDebt.
Workflow Examples
Borrower Flow
CODEBLOCK22
LP Flow
CODEBLOCK23
Common Errors & Recovery
| Error | Cause | Recovery |
|---|
| INLINECODE58 | Env var missing | Set WALLET_PRIVATE_KEY before running |
| INLINECODE60 |
amount > availableCredit | Call
status, borrow less |
|
Insufficient balance | Wallet has no USDC | Bridge funds or acquire testnet USDC |
|
Insufficient liquidity | Pool is fully utilized | Wait for borrowers to repay or LPs to deposit |
|
Nonce too low | Transaction conflict | Wait 10 seconds and retry |
|
Bridge timeout | Circle Bridge delay | Wait 5-10 minutes, check balances on both chains |
|
Same chain error |
from === to in bridge | Use different source and destination |
References
- - See
references/contracts.md for full ABIs and type definitions. - See
scripts/client.ts and scripts/lp.ts for implementation.
Credex 协议技能
与 Credex 协议交互——Arc 网络上 AI 代理的去中心化信用系统。
使用方法
基础目录: {baseDir}(包含此 SKILL.md 的目录)
从项目根目录运行所有命令:
bash
cd {baseDir}
npx ts-node scripts/client.ts [args] # 借款人命令
npx ts-node scripts/lp.ts [args] # 流动性提供者命令
输出格式: 所有脚本返回 JSON 格式以便机器读取。解析输出以提取 creditLimit、txHash、debt 等字段。
环境变量
必需(必须设置)
| 变量 | 描述 |
|---|
| WALLETPRIVATEKEY | 用于签署交易的私钥。没有此密钥,所有命令都将失败。 |
| RPC_URL |
Arc 网络 RPC。默认值:https://rpc.testnet.arc.network |
可选
| 变量 | 描述 | 默认值 |
|---|
| CREDEXPOOLADDRESS | 池合约地址 | 0x32239e52534c0b7e525fb37ed7b8d1912f263ad3 |
| CREDEXAGENTURL |
Credex 代理服务器 URL | http://localhost:10003 |
运行前检查: 在运行任何命令之前,请确认已设置 WALLETPRIVATEKEY。如果缺失,请提示用户。
合约地址(Arc 测试网)
| 合约 | 地址 |
|---|
| CredexPool | 0x32239e52534c0b7e525fb37ed7b8d1912f263ad3 |
| USDC(Arc) |
0x3600000000000000000000000000000000000000 |
| USDC(Base Sepolia)| 0x036CbD53842c5426634e7929541eC2318f3dCF7e |
客户端命令(借款人)
脚本: scripts/client.ts
运行方式: npx ts-node scripts/client.ts [args]
status
检查代理的信用状态。
使用方法:
bash
npx ts-node scripts/client.ts status
参数:
- - address(可选):钱包地址。默认为 WALLETPRIVATEKEY 对应的地址。
返回: JSON
json
{
creditLimit: 100.000000,
principal: 5.000000,
interest: 0.050000,
debt: 5.050000,
availableCredit: 95.000000,
active: true,
frozen: false
}
操作: 在调用 borrow 之前,使用 availableCredit 检查是否有足够的资金。
borrow
从池中借入 USDC。
使用方法:
bash
npx ts-node scripts/client.ts borrow
参数:
- - amount(必需):USDC 金额,以十进制字符串形式提供(例如 5.0)。
返回: JSON
json
{
success: true,
txHash: 0x...,
borrowed: 5.000000,
newDebt: 5.000000,
availableCredit: 95.000000
}
失败条件: amount > availableCredit。请先检查 status。
repay
偿还池中的债务。
使用方法:
bash
npx ts-node scripts/client.ts repay
参数:
- - amount:要偿还的特定 USDC 金额(例如 5.0)。
- all:计算总债务加 1% 缓冲并全额偿还。合约将按实际欠款金额进行上限处理。
返回: JSON
json
{
success: true,
txHash: 0x...,
repaid: 5.050000,
remainingDebt: 0.000000,
newCreditLimit: 110.000000
}
注意: 还款优先偿还 利息,然后偿还 本金。每次成功还款将使信用额度增加 10%。
bridge
在 Arc 测试网和 Base Sepolia 之间桥接 USDC。
使用方法:
bash
npx ts-node scripts/client.ts bridge
参数:
- - amount:USDC 金额(例如 10.0)。
- from:源链(arc 或 base)。
- to:目标链(arc 或 base)。
返回: JSON
json
{
success: true,
amount: 10.000000,
from: Arc_Testnet,
to: Base_Sepolia,
estimatedArrival: 5-10 minutes
}
失败条件: from === to。链必须不同。
balance
检查两条链上的钱包余额。
使用方法:
bash
npx ts-node scripts/client.ts balance
返回: JSON
json
{
arc: 50.000000,
base: 25.000000,
total: 75.000000
}
LP 命令(流动性提供者)
脚本: scripts/lp.ts
运行方式: npx ts-node scripts/lp.ts [args]
pool-status
检查池的整体健康状况和指标。
使用方法:
bash
npx ts-node scripts/lp.ts pool-status
返回: JSON
json
{
totalAssets: 1000.000000,
totalLiquidity: 800.000000,
totalDebt: 200.000000,
totalShares: 950.000000,
sharePrice: 1.052631,
utilizationPercent: 20
}
deposit
存入 USDC 以接收 LP 份额。
使用方法:
bash
npx ts-node scripts/lp.ts deposit
参数:
- - amount:要存入的 USDC(例如 100.0)。
返回: JSON
json
{
success: true,
txHash: 0x...,
deposited: 100.000000,
sharesReceived: 95.000000,
totalShares: 95.000000
}
withdraw
销毁 LP 份额以提取 USDC。
使用方法:
bash
npx ts-node scripts/lp.ts withdraw
参数:
- - shares:要销毁的份额数量(例如 50.0)。
- all:根据可用流动性提取最大可能金额。
返回: JSON
json
{
success: true,
txHash: 0x...,
sharesBurned: 50.000000,
usdcReceived: 52.631579,
remainingShares: 45.000000
}
注意: 如果流动性被完全利用(所有 USDC 已借出),提取可能会受到上限限制。
lp-balance
检查地址的 LP 头寸。
使用方法:
bash
npx ts-node scripts/lp.ts lp-balance [address]
返回: JSON
json
{
shares: 95.000000,
value: 100.000000
}
协议机制
利息累积
- - 利率: 每个间隔 0.1%(10 个基点)
- 间隔: 1 分钟(测试网加速)
- 公式: debt = principal + accrued_interest
信用额度增长
每次还款后:
newLimit = currentLimit × 1.10
最大值:10,000 USDC。
可用信用额度
availableCredit = creditLimit - principal
利息不会减少借款能力——只有本金会。
份额价格(LP)
sharePrice = totalAssets / totalShares
其中 totalAssets = liquidity + outstandingDebt。
工作流程示例
借款人流程
text
- 1. 检查状态 → npx ts-node scripts/client.ts status
- 借款 → npx ts-node scripts/client.ts borrow 5
- 使用资金 →(在 Arc