Ember 协议 SDK
用于在SUI和SUI上与 Ember 协议交互的综合性类型脚本 SDK EVM相容区块链. 这个SDK提供了一整套管理金库的工具, 处理用户操作,并管理协议.
概览
Ember 协议 SDK 是一个 TypeScript 库,使开发者能够与 ember协议在SUI和EVM兼容区块链上的金库系统。 协议 允许用户将资产存入金库,接受股票并参与 生产战略.
支持的链条
- 苏伊 - 全力支持SUI区块链
- EVM( 视频) - 支持Ethereum和EVM兼容链(使用醚.js v6)
- EVM金库执行 ERC-4626 (韩语) 象征性金库标准
- 保险库合同本身是股票代号(ERC20)
建筑
SDK是围绕几个关键类别建造的:
- 嵌入断层: 金库互动的主要切入点(支持SUI和EVM)
- 管理呼叫: 礼宾管理的行政职能
- 用户呼叫: 存款和提款的用户查询业务
- 操作员呼叫: 用于金库管理的操作员功能
- 默认提醒: 特定故障的行政职能
- Tx 构建器: 交易楼公用事业
安装
npm install @ember-finance/sdk
或者说
yarn add @ember-finance/sdk
使用量
SUI 链 - 用户存款示例
import { EmberVaults } from "@ember-finance/sdk";
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
// Setup SUI client and signer
const suiClient = new SuiJsonRpcClient({
url: "https://fullnode.mainnet.sui.io",
network: "mainnet"
});
const keypair = Ed25519Keypair.fromSecretKey(privateKeyBytes);
// Initialize EmberVaults for SUI
const ember = new EmberVaults({
chainType: "sui",
network: "mainnet",
suiClient,
signer: keypair,
environment: "prod" // "prod" | "staging" | "dev"
});
// Fetch deployment configuration from API
await ember.init();
// Get vault information
const vaultId = ember.parser.getVaultIdFromName("USDC Vault");
// Deposit assets into the vault
const depositAmount = "1000000"; // 1 USDC (6 decimals)
const result = await ember.user.depositAsset(vaultId, depositAmount);
console.log("Deposit successful:", result);
EVM链 - 用户存款示例(ERC-4626)
EVM金库执行ERC-4626标志化金库标准. 保险库合同本身 是股票代币,所以没有单独的收款代币.
传统办法(两个交易)
import { EmberVaults } from "@ember-finance/sdk";
import { ethers } from "ethers";
// Setup ethers provider and signer
const provider = new ethers.JsonRpcProvider("https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY");
const signer = new ethers.Wallet(privateKey, provider);
// EVM deployment configuration (can be fetched from API or provided directly)
const deployment = {
network: "ethereum",
chainId: "1",
contracts: {
protocolConfig: {
proxyAddress: "0x...",
// ... other config
},
vaults: {
"USDC Vault": {
proxyAddress: "0x...",
baseToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
// ... other config
}
},
receiptTokens: {
// Note: For ERC-4626, the vault is the share token
}
}
};
// Initialize EmberVaults for EVM
const ember = new EmberVaults({
chainType: "evm",
signer,
provider,
deployment,
environment: "prod"
});
// Or fetch deployment from API
// await ember.init();
const vaultAddress = deployment.contracts.vaults["USDC Vault"].proxyAddress;
const underlyingAsset = deployment.contracts.vaults["USDC Vault"].baseToken;
const depositAmount = "1000000"; // 1 USDC (6 decimals)
// Step 1: Approve token spending (required for EVM)
await ember.user.approveTokenMax(underlyingAsset, vaultAddress);
// Step 2: Deposit assets (ERC-4626 standard: deposit(assets, receiver))
// Receiver defaults to caller
const result = await ember.user.deposit(vaultAddress, depositAmount);
console.log("Deposit successful:", result);
// Optional: Wait for receipt and get events
const resultWithEvents = await ember.user.deposit(
vaultAddress,
depositAmount,
{ waitForReceipt: true }
);
console.log("Events:", resultWithEvents.events);
新方法:EIP-2612许可单项交易(建议)
新的 depositWithPermit 财务报告和审定财务报表 mintWithPermit 允许存入 单人
交易 无需另行批准交易。 使用 EIP- 2612 许可
签名.
import { EmberVaults, signPermitSimple } from "@ember-finance/sdk";
import { ethers } from "ethers";
// Setup (same as above)
const provider = new ethers.JsonRpcProvider("https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY");
const signer = new ethers.Wallet(privateKey, provider);
const ember = new EmberVaults({
chainType: "evm",
signer,
provider,
deployment,
environment: "prod"
});
const vaultAddress = deployment.contracts.vaults["USDC Vault"].proxyAddress;
const underlyingAsset = deployment.contracts.vaults["USDC Vault"].baseToken;
const depositAmount = "1000000"; // 1 USDC (6 decimals)
// Generate permit signature (off-chain, no gas cost)
const permitSig = await signPermitSimple(
signer,
underlyingAsset,
"USD Coin", // Token name (must match token's EIP-2612 name)
vaultAddress,
depositAmount
);
// null means the token's permit domain couldn't be verified against its
// DOMAIN_SEPARATOR(), so the permit would be rejected: approve + deposit instead
let result;
if (permitSig) {
// Deposit with permit in a SINGLE transaction (no separate approval needed!)
result = await ember.user.depositWithPermit(vaultAddress, depositAmount, permitSig);
} else {
await ember.user.approveToken(underlyingAsset, vaultAddress, depositAmount);
result = await ember.user.deposit(vaultAddress, depositAmount);
}
console.log("Deposit successful:", result);
EVM - 存入不同的接收器
// Deposit, with shares going to a different address
const result = await ember.user.deposit(
vaultAddress,
depositAmount,
{ receiver: "0xRecipientAddress..." }
);
EVM - 薄荷特定股份(ERC-4626)
传统办法(需要核准)
// Mint a specific number of shares (vault will pull required assets)
const sharesToMint = "1000000000000000000"; // 1e18 shares
// Must approve first
await ember.user.approveTokenMax(underlyingAsset, vaultAddress);
await ember.user.mint(vaultAddress, sharesToMint);
// Mint to a different receiver
await ember.user.mint(vaultAddress, sharesToMint, {
receiver: "0xRecipientAddress..."
});
持有许可证的单一交易
import { signPermitSimple } from "@ember-finance/sdk";
const sharesToMint = "1000000000000000000"; // 1e18 shares
// Generate permit signature for a high amount (vault will pull exact amount needed)
const permitSig = await signPermitSimple(
signer,
underlyingAsset,
"USD Coin",
vaultAddress,
"115792089237316195423570985008687907853269984665640564039457584007913129639935" // max uint256
);
// null means the token's permit domain couldn't be verified: use the two-step
// approve + mint flow above instead
if (permitSig) {
// Mint with permit in single transaction
await ember.user.mintWithPermit(vaultAddress, sharesToMint, permitSig);
// Or mint to a different receiver
// await ember.user.mintWithPermit(vaultAddress, sharesToMint, permitSig, {
// receiver: "0xRecipientAddress..."
// });
}
EVM - Redeem 股份( 初始退出)
// Redeem shares to initiate a withdrawal request
// Note: Withdrawal requests are processed by operators, not immediate
const shares = "500000000000000000000"; // shares to redeem
// Redeem to self (default)
await ember.user.redeemShares(vaultAddress, shares);
// Redeem to a different receiver
await ember.user.redeemShares(vaultAddress, shares, {
receiver: "0xRecipientAddress..."
});
类型安全链访问
// Check chain type at runtime
if (ember.isSui()) {
// TypeScript knows this is SUI
const suiClient = ember.suiClient;
// ... SUI-specific operations
}
if (ember.isEvm()) {
// TypeScript knows this is EVM
const provider = ember.provider;
// ... EVM-specific operations
}
// Get strongly-typed chain-specific instance
const suiEmber = ember.asSui(); // throws if not SUI
const evmEmber = ember.asEvm(); // throws if not EVM
核心组成部分
嵌入断层
与Ember协议互动的主要切入点:
// Common properties available for both chains
ember.chainType // "sui" | "evm"
ember.vaultsApi // VaultsApi - same for both chains
ember.api // AccountsApi - same for both chains
ember.parser // Deployment parser (chain-specific)
ember.txBuilder // Transaction builder (chain-specific)
ember.admin // Admin calls (chain-specific)
ember.operator // Operator calls (chain-specific)
ember.vaultAdmin // Vault admin calls (chain-specific)
ember.user // User calls (chain-specific)
ember.deployment // Deployment config (chain-specific)
用户操作( 用户呼叫)
处理用户界面金库操作 :
EVM(ERC-4626): (英语)
- 存款:存款资产和接受股份(ERC-4626标准,需要批准)
- 使用许可证的存款: 使用EIP-2612许可证交存资产(单笔交易,否) (需要核准) 新建
- 薄荷: 薄荷特定股份,通过交存所需资产(ERC-4626标准, 需要核准)
- 薄荷与许可: 使用 EIP- 2612 许可的薄荷股票(单笔交易,无批准) (所需) 新建
- 赎回股份: Redeem 股份启动退出请求
- 取消 Pending 撤消请求: 取消待定的退出请求
- 核准托肯: 核准象征性支出
- 批准 TokenMax 程序: 核准最高象征性支出
许可证公用事业: ✨ 新建
- 签名: 生成 EIP- 2612 自动退出的许可签名, 截止日期
和 EIP-712 域;返回
null如果域与符号不符DOMAIN_SEPARATOR() - 签名许可: 生成 EIP- 2612 允许自定义参数签名
- 解析软件域: 获得一个令牌的EIP-712许可域(EIP-5267)
eip712Domain(), (中文(简体) ), 其他符号名称version(),默认为"1"(中文(简体) ) - 获取珀米特诺斯: 为用户获取当前许可非ce
苏伊:
- 存款: 将资产存入金库
- 薄荷股份: 有特定金额的薄荷金库股票
- 赎回股份: 基础资产的Redeem股份
- 取消 Pending 撤消请求: 取消待定的退出请求
管理函数( adminCalls)
礼宾一级的行政职能:
- 更新MaxFee 百分比: 更新协议收费限制
- 暂停非辅助操作: 紧急协议控制
- 更新PlatformFee 接收器: 更新收费接受者
- 设置黑名单账户: 管理黑名单账户
- 更新断层: 更新金库管理员地址
操作函数( 操作器呼叫)
故障操作员管理职能:
- 收集公式Fee: 收取累计费用
- 进程: 处理待决退出
- 更新断层: 更新金库汇率(利率管理者角色)
- 退出空壳而退出: 退出用于战略执行
断层管理函数( VaultAdminCalls)
特定故障的行政管制(称为通过EVM上的《议定书》):
- 更新可刷新共享: 配置最小提款量
- 设置默认子账户: 管理金库子账户
- 更新断层操作器: 更改金库运算符
- 更新断层管理器: 变化率管理器
- 默认状态: 暂停/不暂停金库业务
- 更新: 更新金库收费百分比
- 更新虚拟MaxTVL: 更新最大 TVL
- 更新更新更新时间间隔: 更新速率更新间隔
- 更新错误Name: 更新金库名称
EIP-2612 许可证支助 新建
安伯金库现在支持 EIP-2612 许可签名,允许用户存入或 薄荷股份a 单笔交易 无需另行批准交易. 这大大提高了用户的经验:
- 减少天然气成本(一项交易而不是两项)
- 消除等待核准交易确认的必要性
- 提供更平稳、更快的存款流量
许可证如何运作
EIP- 2612 允许用户签署授权金库的脱链消息( 无气体成本) 用来花他们的代币。 此签名随后列入存款/薄荷交易, 它既处理批准问题,又处理存款问题.
使用 SDK 许可证
import { EmberVaults, signPermitSimple } from "@ember-finance/sdk";
// 1. Generate permit signature (off-chain, no gas)
const permitSig = await signPermitSimple(
signer,
tokenAddress,
"USD Coin", // Token name (must match EIP-2612 name)
vaultAddress,
amount
);
// 2. Deposit with permit (single transaction), or approve + deposit if no permit
if (permitSig) {
await ember.user.depositWithPermit(vaultAddress, amount, permitSig);
} else {
await ember.user.approveToken(tokenAddress, vaultAddress, amount);
await ember.user.deposit(vaultAddress, amount);
}
高级许可使用
对于许可参数的更多控制:
import { signPermit, getPermitNonce } from "@ember-finance/sdk";
// Get current nonce for the user
const nonce = await getPermitNonce(tokenAddress, userAddress, provider);
// Set custom deadline (e.g., 24 hours from now)
const deadline = BigInt(Math.floor(Date.now() / 1000) + 86400);
// Get chain ID
const network = await provider.getNetwork();
const chainId = network.chainId;
// Sign permit with custom parameters
const permitSig = await signPermit(
signer,
tokenAddress,
"USD Coin",
vaultAddress,
amount,
deadline,
nonce,
chainId
);
// Use the permit
await ember.user.depositWithPermit(vaultAddress, amount, permitSig);
重要说明
- 脚本支持:基础标志必须支持EIP-2612许可. 大部分现代符号 (USDC,DAI等)支持本标准.
- 脚本名称: 用于执行EIP-5267的标志
eip712Domain(),域名读取 从标志和您通过的名称被忽略。 对于其他符号,名称必须匹配 代号是EIP-2612域名. - 版本: 如果符号没有
version(), (中文(简体) ),"1"假设。 过version改为signPermit要覆盖;然后按照给定的准确使用域. - 无许可证数字 :
signPermitSimple对照符号检查域名DOMAIN_SEPARATOR()返回时null如果两者不同 退后批准+存款.signPermit不进行此检查. - 截止日期:许可签名有一个最后期限. 在截止日期之后,签署 变成无效.
- 诺斯:每次许可签名都使用非ce. 一旦使用,非ce 递增和 无法重用签名 .
ERC-4626 相容性(EVM)
EVM金库完全符合ERC-4626:
| ERC-4626 方法 | SDK 方法 | 页:1 |
|---|---|---|
asset() | - 说吧 | 返回基本资产地址 |
deposit(assets, receiver) | user.deposit(vault, assets, {receiver?}) | 存款资产,获得股份 |
mint(shares, receiver) | user.mint(vault, shares, {receiver?}) | 投放资产的薄荷股票 |
withdraw(assets, receiver, owner) | 不详 | 不支持, 使用 redeemShares |
redeem(shares, receiver, owner) | 不详 | 不支持, 使用 redeemShares |
totalAssets() | - 说吧 | 通过合同阅读 |
convertToShares(assets) | - 说吧 | 通过合同阅读 |
convertToAssets(shares) | - 说吧 | 通过合同阅读 |
previewDeposit(assets) | - 说吧 | 通过合同阅读 |
previewMint(shares) | - 说吧 | 通过合同阅读 |
注:标准ERC-4626 withdraw 财务报告和审定财务报表 redeem 由于金库的自动同步,不支持
退出机制。 使用 redeemShares 提出撤回请求,即
由金库操作员处理.
释放
SDK住在这里 木质摩诺 时间
typescript/library/ember-sdk。 。 。 . @ember-finance/sdk 由独行侠出版
.github/workflows/ember_sdk_publish.yaml 使用 npm OIDC 信任的出版 。 没有
npm 令牌 — npm 授权一个工作流程文件按确切文件名进行, 所以所有三个文件都发布
路径存在其中,文件不得被重新命名.
| 意图 | 行动 | 调值 |
|---|---|---|
| 释放 | 合并到 main 抚摸 typescript/library/ember-sdk | latest |
| 释放前 | 推动标签 pre-release-ember-sdk-<version> | pre-release |
| 重试出版物 | 运行工作流程,选择一个 dist_tag | 选择 |
弹出 version 内 package.json 在 PR. npm 版本中是不可改变的,所以工作流程
如果该版本已经发布, 则提前失败; 要重试失败的发布, 请发送
工作流程而不是推另一个标签.
许可证
这个项目根据Apache许可证2.0获得许可——见 自由主义 文件 详细情况.
由Ember协议团队建造