DeFi 保护器位置 SDK
支持的协议 :
设置
所支持的节点版本为v10.
- 运行
npm install(初次) - 运行
npm run build
build 命令将生成合同并构建 ejs 和 esm 文件夹
如何使用
这是一个化合物 V3 的例子, 所有其他协议都相似
import { compoundV3 } from '@defisaver/positions-sdk';
// every protocol has market data and user data getters
const {
getCompoundV3MarketsData,
getCompoundV3AccountData,
} = compoundV3;
const provider = 'Your RPC provider';
const user = '0x123...';
const { assetsData } = await getCompoundV3MarketsData(
provider, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
1, // network
selectedMarket, // market object like in /src/markets/compound/index.ts
provider, // this must be mainnet rpc - used for getting prices onchain and calculating apys
);
const userData = await getCompoundV3AccountData(
provider,
1, // network
userAddress, // EOA or DSProxy
'', // proxy address of the user, or just empty string if checking for EOA
{
selectedMarket, // market object as in /src/markets/compound/index.ts
assetsData,
}
);
找到更多实例 这里
测试
npm run test - 进行所有测试
npm run test-single --name=your_test_name - 运行指定名称的单一测试,例如 My Test.js 测试名称为 My Test