0.4.10 • Published 11 months ago

@defund-protocol/v1-sdk v0.4.10

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

v1-sdk

DeFund Protocol v1 SDK

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

Swap Params

ParamTypeDescription
makerAddressyour signer address
fundAddressAddressyour fund address
swapDetailsSwapDetails
overridesOverrides

Swap Details

ParamTypeDescription
opTypestringexactInput, exactOutput
tokenInAddress
tokenOutAddress
amountInBigNumberamountIn for exactInput, amountInMaximum for exactOutput
amountOutBigNumberamountOutMinimum for exactInput, amountOut for exactOutput
useNativeBooleanset to true if you want to swap to or from native Token instead of warpped native Token
expirationnumberoptional, default expires in 10 minutes

Overrides

You can find out more about the overrides parameter from the ethers document

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 native token, use ETH in this demo
  expiration: Math.round(new Date().getTime() / 1000 + 30 * 60) // 30 minutes
};

const overrides = {};

const tx = await sdk.executeSwap(maker, fundAddress, swapDetails, overrides);

AssetsConvert

Convert Params

ParamTypeDescription
makerAddressyour signer address
fundAddressAddressyour fund address
convertDetailsConvertDetails
overridesOverrides

Convert Details

ParamTypeDescription
rationumberratio of tokenIn
tokenInAddress
tokenOutAddress
slippagenumber1 for 1%, minimum is 0.01 for 0.01%
useNativeBooleanset to true if you want to swap to or from native Token instead of warpped native Token
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
};

const overrides = {};

const tx = await sdk.executeAssetsConvert(
  maker,
  fundAddress,
  convertDetails,
  overrides
);

ApproveToken

Approve Token Params

ParamTypeDescription
makerAddressyour signer address
fundAddressAddressyour fund address
approveDetailsApproveDetails
overridesOverrides

Approve Details

ParamTypeDescription
opTypestringlocked to fund for now
tokenAddressyour token address
amountBigNumberOptional, default value is MaxInt256
const maker = signer.address;
const fundAddress = 'your fund address';
const approveDetails = {
  opType: 'fund',
  token: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH Address on mainnet
};

const overrides = {};

const tx = await sdk.executeApproveToken(
  maker,
  fundAddress,
  approveDetails,
  overrides
);

GetFundAssets

You can use this method to get the asset information of the fund

const maker = signer.address;
const fundAddress = 'your fund address';

const assets = await sdk.getFundAssets(fundAddress);

GetFundInfo

You can use this method to get all the on-chain information of the fund

Params

ParamTypeDescription
fundAddressAddress
lpAddressAddressOptional, If you want to get share information about a specific lp, pass this parameter
withAssetsBooleanThe default is true, return all information, if you don't need asset information, you can pass false
const maker = signer.address;
const fundAddress = 'your fund address';

const lpAddress = 'this address of specific lp';
const witAssets = false;

const assets = await sdk.getFundAssets(fundAddress, lpAddress, withAssets);

Approve Token

const maker = signer.address;
const fundAddress = 'your fund address';

const tx = await sdk.executeApproveToken(maker, fundAddress, {token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'});

If approve is not required, tx returns null, otherwise returns the transaction.

Buy Fund

const maker = signer.address;
const fundAddress = 'your fund address';
const amount = BigNumber.from("10000000000000000") // 0.01 ETH

const tx = await sdk.executeBuyFund(
  maker,
  fundAddress,
  amount,
);

Sell Fund

const maker = signer.address;
const fundAddress = 'your fund address';
const amount = BigNumber.from("10000000000000000") // 0.01 ETH

const tx = await sdk.executeSellFund(
  maker,
  fundAddress,
  10, // 10 percent
);

Get Your Funds list

Role

RoleValueDescription
Manager1funds you manage
Operator2funds you can operate
Investor3funds you invest in
  const managerList = await sdk.getFundList(signer.address, 1);
  const operatorList = await sdk.getFundList(signer.address, 2);
  const investorList = await sdk.getFundList(signer.address, 3);

Get Fund's Lps

const fundAddress = 'your fund address';
const lps = await sdk.getFundInvestors(fundAddress);

Examples

Examples can be found at: Examples

0.4.10

11 months ago

0.4.9

11 months ago

0.4.8

11 months ago

0.4.5

12 months ago

0.4.4

12 months ago

0.4.7

12 months ago

0.4.6

12 months ago

0.5.0-beta.1

1 year ago

0.5.0-beta.0

1 year ago

0.5.0

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago