返回顶部
o

orderly-deposit-withdraw有序存取跨链

Handle token deposits and withdrawals across chains, including allowance approval, vault interactions, and cross-chain operations

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

orderly-deposit-withdraw

Orderly Network: 存款与提现

本技能涵盖在Orderly Network上存入和提取资产,包括代币授权、金库交互、跨链操作和内部转账。

使用场景

  • - 构建存款/提现界面
  • 管理抵押品
  • 实现跨链转账
  • 处理代币授权
  • 账户间内部转账

前置条件

  • - 已连接的Web3钱包(EVM或Solana)
  • 支持的链上的代币
  • 理解ERC20授权模式
  • 用于API操作的Ed25519密钥对

支持的链与代币

链IDUSDCUSDT
Arbitrum42161
Optimism
10 | ✅ | ✅ | | Base | 8453 | ✅ | ✅ | | Ethereum | 1 | ✅ | ✅ | | Mantle | 5000 | ✅ | - | | Solana | 900900900 | ✅ | - |

注意:使用 GET /v1/public/chaininfo?brokerid={yourbrokerid} 动态获取支持的链

存款流程

  1. 1. 获取链信息
  2. 检查代币是否为原生代币(ETH、SOL)
  3. 授权代币额度(若非原生代币)
  4. 计算brokerHash和tokenHash
  5. 从金库获取存款费用
  6. 执行带费用的存款交易
  7. 等待确认
  8. Orderly余额更新

React SDK:完整存款工作流

第1步:获取链信息

typescript
import { useChain } from @orderly.network/hooks;

function DepositForm() {
const { chains, isLoading } = useChain(USDC);

if (isLoading) return

加载链信息中...
;

return (

);
}

第2步:获取存款元数据

typescript
import { useDeposit } from @orderly.network/hooks;

function DepositInfo({ tokenSymbol }: { tokenSymbol: string }) {
const { symbol, address, decimals, chainId, network } = useDeposit(tokenSymbol);

if (!address) return

加载存款信息中...
;

return (


存入 {symbol}


网络:{network}


链ID:{chainId}


合约地址:{address}


小数位数:{decimals}


仅向此地址发送 {symbol}({network}网络)。


);
}

第3步:通过合约执行存款

typescript
import { ethers } from ethers;

const ERC20_ABI = [
function approve(address spender, uint256 amount) returns (bool),
function allowance(address owner, address spender) view returns (uint256),
function balanceOf(address owner) view returns (uint256),
];

const VAULT_ABI = [
function deposit(tuple(bytes32 accountId, bytes32 brokerHash, bytes32 tokenHash, uint256 tokenAmount) input) external payable,
function getDepositFee(address account, tuple(bytes32 accountId, bytes32 brokerHash, bytes32 tokenHash, uint256 tokenAmount) input) view returns (uint256),
];

async function depositUSDC(
provider: ethers.BrowserProvider,
amount: string,
vaultAddress: string,
usdcAddress: string,
brokerId: string,
orderlyAccountId: string
) {
const signer = await provider.getSigner();
const userAddress = await signer.getAddress();

// 1. 授权代币
const usdc = new ethers.Contract(usdcAddress, ERC20_ABI, signer);
const amountWei = ethers.parseUnits(amount, 6);
const allowance = await usdc.allowance(userAddress, vaultAddress);

if (allowance < amountWei) {
console.log(正在授权USDC...);
const approveTx = await usdc.approve(vaultAddress, ethers.MaxUint256);
await approveTx.wait();
console.log(授权完成);
}

// 2. 计算哈希值
const encoder = new TextEncoder();
const brokerHash = ethers.keccak256(encoder.encode(brokerId));
const tokenHash = ethers.keccak256(encoder.encode(USDC));

// 3. 创建存款输入结构体
const depositInput = {
accountId: orderlyAccountId,
brokerHash: brokerHash,
tokenHash: tokenHash,
tokenAmount: amountWei,
};

// 4. 获取存款费用
const vault = new ethers.Contract(vaultAddress, VAULT_ABI, signer);
const depositFee = await vault.getDepositFee(userAddress, depositInput);
console.log(存款费用:, ethers.formatEther(depositFee), ETH);

// 5. 执行带费用的存款
console.log(正在存款...);
const depositTx = await vault.deposit(depositInput, { value: depositFee });
const receipt = await depositTx.wait();
console.log(存款完成:, receipt.hash);

return receipt;
}

REST API:获取存款信息

typescript
// 获取支持的代币及其抵押因子
GET /v1/public/token

// 响应
{
success: true,
data: {
rows: [
{
token: USDC,
decimals: 6,
address: {
42161: 0xaf88d065e77c8cC2239327C5EDb3A432268e5831,
10: 0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85
},
collateral_factor: 1.0
},
{
token: USDT,
decimals: 6,
address: { ... },
collateral_factor: 0.95
}
]
}
}

// 获取链信息
GET /v1/public/chaininfo?brokerid={broker_id}

// 获取金库余额(TVL)
GET /v1/public/vault_balance

理解抵押因子

每个代币都有一个抵押因子(0.0到1.0),它决定了你的存款中有多少可以算作交易抵押品:

代币抵押因子$1000存款 = 抵押价值
USDC1.0 (100%)$1000
USDT
0.95 (95%) | $950 |
| 其他 | 各不相同 | 取决于风险评估 |

示例:如果你存入$1000的USDT,抵押因子为0.95,则只有$950算作保证金计算的抵押品。

提现流程

  1. 1. 获取提现nonce
  2. 使用EIP-712(EVM)或Ed25519(Solana)签署提现消息
  3. 使用Ed25519 API认证提交已签名的请求
  4. 等待处理
  5. 在链上接收代币

React SDK:useWithdraw Hook

typescript
import { useWithdraw } from @orderly.network/hooks;

function WithdrawForm() {
const { withdraw, isLoading } = useWithdraw();

const [amount, setAmount] = useState();
const [destination, setDestination] = useState();

const handleWithdraw = async () => {
try {
await withdraw({
symbol: USDC,
amount: 50,
address: 0x123...,
chainId: 1, // 以太坊主网
network: ethereum
});
alert(提现已发起!);
} catch (error) {
console.error(提现失败:, error);
}
};

return (


type=text
placeholder=金额
value={amount}
onChange={(e) => setAmount(e.target.value)}
/>

type=text
placeholder=目标地址
value={destination}
onChange={(e) => setDestination(e.target.value)}
/>

标签

skill ai

通过对话安装

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

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 orderly-deposit-withdraw-1776199441 技能

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

设置 SkillHub 为我的优先技能安装源,然后帮我安装 orderly-deposit-withdraw-1776199441 技能

通过命令行安装

skillhub install orderly-deposit-withdraw-1776199441

下载

⬇ 下载 orderly-deposit-withdraw v1.0.0(免费)

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

v1.0.0 最新 2026-4-15 11:10
Orderly Network: Deposit & Withdraw v1.0.0

- Initial release enabling deposit and withdrawal of assets across supported EVM and Solana chains.
- Includes token approvals, vault interaction, internal transfers, and full cross-chain operation support.
- Provides React SDK hooks and code samples for both deposit and withdrawal flows.
- Details API endpoints for dynamic chain/token info, collateral factor handling, and withdrawal nonce management.
- Outlines native and ERC20 token flows, fees, and margin collateral considerations.

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

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

p2p_official_large
返回顶部