DeFi 保护程序 SDK
将动作构建为DeFi Saver智能钱包的配方.
安装
npm install @defisaver/sdk
示例
编码一个将 0.1 ETH 包裹在 Ethereum 上的 WETH 的食谱 :
const { configure, Recipe, actions } = require('@defisaver/sdk');
async function main() {
configure({ chainId: 1, testingMode: false });
const recipe = new Recipe('Wrap ETH', [
new actions.basic.WrapEthAction('100000000000000000'),
]);
const [target, data] = recipe.encodeForDsProxyCall();
const value = await recipe.getEthValue();
console.log({ target, data, value });
}
main().catch(console.error);
量用符号基单位作为小数字符串. 这里, value 是Wei中的ETH数量. target 财务报告和审定财务报表 data 是智能钱包的参数 execute(address,bytes) 调用; 编码不提交交易 .
测试
从本地退出中安装依赖性 npm ci,然后运行 :
# Run offline tests (no RPC required)
npm run test:unit
# Run all tests, including RPC-dependent wallet tests
npm test
# Run a single test file (test/Recipe.js)
npm run test-single --name=Recipe
整个套房需要 RPC 环境或当地环境 .env 用于钱包测试的文件。 指向局部或叉入的测试链.
大楼
npm run build
构建包并运行有自动修正的 Lint 。 在不更改文件的情况下检查插件, 使用 npm run lint-check。 。 。 .