developers
To assist capable developers in using DeFund to develop and customize their own fund management strategies, we have officially released the DeFund V1 SDK toolkit. This toolkit will facilitate users to customize their own fund strategies for investment, without having to use our provided user interface.
SDK
Supported chains
ChainId | Name |
---|---|
1 | mainnet |
5 | goerli |
137 | matic |
80001 | mumbai |
Supported Pools & Tokens
See details Pools & Tokens
Installation
npm install @defund-protocol/v1-sdk
How to use
Base
SDK initialization requires the following parameters
Param | type | description |
---|---|---|
chainId | number | 1 for mainnet, 5 for goerli, 137 for matic, 80001 for mumbai |
signer | Signer |
import { UniversalSDK } from "@defund-protocol/v1-sdk";
import { Wallet, providers } from "ethers";
const chainId = 1;
const provider = new providers.JsonRpcProvider("your json rpc url");
const signer = new Wallet("your signer privateKey", provider);
const sdk = new UniversalSDK(chainId, signer);
Swap
The Swap method is used for token swapping and currently supports two methods, exactInput and exactOutput. Users can choose the specific corresponding method based on their needs, and need to provide the slippage parameter, which currently has no default value and has to be passed by the user.
Swap Params
Param | Type | Description |
---|---|---|
maker | Address | your signer address |
fundAddress | Address | your fund address |
swapDetails | SwapDetails | |
overrides | Overrides |
Swap Details
Param | Type | Description |
---|---|---|
opType | string | exactInput , exactOutput |
tokenIn | Address | |
tokenOut | Address | |
amountIn | BigNumber | This option is required when opType is exactInput |
amountOut | BigNumber | This option is required when opType is exactOutput |
slippage | number | When the slippage is 0.1%, fill in 0.1 |
useNative | Boolean | set to true if you want to swap to or from ETH instead of WETH |
expiration | number | optional, default expires in 10 minutes |
Overrides
You can find out more about the overrides parameter from the ethers document (opens in a new tab)
const maker = signer.address;
const fundAddress = "your fund address";
const swapDetails = {
opType: "exactInput",
tokenIn: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH Address on mainnet
tokenOut: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC Address on mainnet
amountIn: BigNumber.from("100000000000000000"), // 0.1 ETH
amountOut: BigNumber.from("1000000"), // 1 USDC
useNative: true, // use ETH
expiration: Math.round(new Date().getTime() / 1000 + 30 * 60), // 30 minutes
};
const overrides = {};
const tx = await sdk.executeSwap(maker, fundAddress, swapDetails, overrides);
AssetsConvert
This method provides users with the ability to convert assets proportionally. Unlike swap, which needs to pass precise swap values, this method can pass a proportional parameter to convert the corresponding tokenIn
into tokenOut
according to the ratio
parameter.
Convert Params
Param | Type | Description |
---|---|---|
maker | Address | your signer address |
fundAddress | Address | your fund address |
convertDetails | ConvertDetails | |
overrides | Overrides |
Convert Details
Param | Type | Description |
---|---|---|
ratio | number | tokenIn 的比例 |
tokenIn | Address | |
tokenOut | Address | |
slippage | number | |
useNative | Boolean | set to true if you want to swap to or from ETH instead of WETH |
expiration | number | optional, default expires in 10 minutes |
const maker = signer.address;
const fundAddress = "your fund address";
const convertDetails = {
opType: "assetsConvert",
tokenIn: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH Address on mainnet
tokenOut: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC Address on mainnet
ratio: 1000, // 10%
useNative: true, // use ETH
};
const overrides = {};
const tx = await sdk.executeAssetsConvert(
maker,
fundAddress,
convertDetails,
overrides
);
Examples
Examples can be found at: Examples (opens in a new tab)