Developers 🔥

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

ChainIdName
1mainnet
5goerli
137matic
80001mumbai

Supported Pools & Tokens

See details Pools & Tokens

Installation

npm install @defund-protocol/v1-sdk

How to use

Base

SDK initialization requires the following parameters

Paramtypedescription
chainIdnumber1 for mainnet, 5 for goerli, 137 for matic, 80001 for mumbai
signerSigner
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

ParamTypeDescription
makerAddressyour signer address
fundAddressAddressyour fund address
swapDetailsSwapDetails
overridesOverrides

Swap Details

ParamTypeDescription
opTypestringexactInput, exactOutput
tokenInAddress
tokenOutAddress
amountInBigNumberThis option is required when opType is exactInput
amountOutBigNumberThis option is required when opType is exactOutput
slippagenumberWhen the slippage is 0.1%, fill in 0.1
useNativeBooleanset to true if you want to swap to or from ETH instead of WETH
expirationnumberoptional, 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

ParamTypeDescription
makerAddressyour signer address
fundAddressAddressyour fund address
convertDetailsConvertDetails
overridesOverrides

Convert Details

ParamTypeDescription
rationumbertokenIn 的比例
tokenInAddress
tokenOutAddress
slippagenumber
useNativeBooleanset to true if you want to swap to or from ETH instead of WETH
expirationnumberoptional, 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)