Funds
A fund is a smart contract that can execute operations. Funds have managers and are useful when a manager needs to create different strategies to operate the portfolios or accounts they are handling. Each fund can represent a unique DeFi investment strategy. For example, a manager can create a low risk fund to lend assets and a high risk fund to do ETH margin trades.
To invest in a fund, a deposit operation needs to be executed and to stop investing a withdraw operation. Accounts, portfolios or any other smart contract can invest in funds. When investing they will receive a fund token which represents an IOU token. For more information on funds operations please visit this page.
Funds' managers can execute operations. There is a main manager who can add and remove other managers. It is recommended to keep main manager accounts secure so, in case another manager account is hacked, the main manager can remove it.
Never send tokens directly to the fund, instead use the deposit and withdraw operations.

Initialization

Create a fund action

An action method to create a new fund.
JavaScript & Node
1
const fund = await defire.actions.createFund({
2
managers: ["0x14EF3651e02D07D576928697cB16746093Ea730e"]
3
});
Copied!
Create object param fields
managers requiredarray of strings
List of fund's managers. There must be at least one manager. First owner will be the main owner.
whitelistedOps optional of strings
List of whitelisted operations addresses. The fund can execute only those operations. Default: list of official operations.
whitelistedAssets optional of strings
List of whitelisted assets addresses. The portfolio can operate only those assets. Default: list of official assets.
Returns
This method returns a Promise which resolves with a fund object.

Get a fund query

A query method to get an existing fund.
JavaScript & Node
1
const fund = await defire.query.getFund("0xFFA86B34110a348Df63bD86852706aF05E618338");
Copied!
Method parameters
address required string
Smart contract address of the fund.
Returns
This method returns a Promise which resolves with a fund object.

Is valid fund query

A query method that checks if an fund is in the registry.
JavaScript & Node
1
const result = await defire.query.isFund("0xFFA86B34110a348Df63bD86852706aF05E618338");
Copied!
Method parameters
address required string
Ethereum address to check if it is a fund.
Returns
This method returns a Promise which resolves with true if the fund is in the registry, otherwise with false.

Fund object

It contains the information, query and action methods about a specific fund.
Object fields
address string
Smart contract address of the fund.

Fund token address query

A query to get the fund token.
JavaScript & Node
1
const address = await fund.query.getToken();
Copied!
Returns
This method returns a Promise which resolves with an address string of the fund token.

Fund token total supply query

A query to get the fund token total supply.
JavaScript & Node
1
const address = await fund.query.getTokenTotalSupply();
Copied!
Returns
This method returns a Promise which resolves with a BN object of the total amount of fund token minted.

Assets query

A query to get the list of assets that the fund holds.
JavaScript & Node
1
const assets = await fund.query.getAssets();
Copied!
Returns
This method returns a Promise which resolves with anarray of string addresses of assets that the fund holds.

Asset balance query

A query to check fund balance of an asset.
JavaScript & Node
1
const balance = await fund.query.balance(defire.Assets.DAI);
Copied!
Method parameters
address required string
Smart contract address of the asset.
Returns
This method returns a Promise which resolves with a BN object of the balance of the asset in wei.

Has an asset query

A query method to check if a fund holds an asset.
JavaScript & Node
1
const result = await fund.query.hasAsset(defire.Assets.DAI);
Copied!
Method parameters
address required string
Smart contract address of the asset.
Returns
This method returns a Promise which resolves with true if the fund has the asset or false if not.

Execute single operation action

An action method to execute one DeFi operation from the fund.
JavaScript & Node
1
const result = await fund.actions.execute(operation);
Copied!
Method parameters
operation required operation object
DeFi operation to be executed.
Returns
This method returns a Promise which resolves with true if the operation execution succeeded or throws an error if it failed.

Execute multiple operations action

An action method to execute many DeFi operations from the fund.
JavaScript & Node
1
const result = await fund.actions.execute(
2
[operation1, operation2, operation3]
3
);
Copied!
Method parameters
operations required array of operation object
DeFi operations to be executed.
Returns
This method returns a Promise which resolves with true if the execution of all operations succeeded or throws an error if it failed.

Add manager action

An action method to add a new manager to the fund.
JavaScript & Node
1
const result = await fund.actions.addManager("0xe5062E38DA29697cb122aAc70320a5847DD83960");
Copied!
Method parameters
address required string
New manager address.
Returns
This method returns a Promise which resolves with true if the manager was added successfully or throws an error if it failed.

Remove manager action

An action method to remove an manager from the fund.
JavaScript & Node
1
const result = await fund.actions.removeManager("0xe5062E38DA29697cb122aAc70320a5847DD83960");
Copied!
Method parameters
address required string
Address of the manager to be removed.
Returns
This method returns a Promise which resolves with true if the manager was removed successfully or throws an error if it failed.

Is manager query

A query method that checks if the address is an manager of the fund.
JavaScript & Node
1
const result = await fund.query.isManager("0xe5062E38DA29697cb122aAc70320a5847DD83960");
Copied!
Method parameters
address required string
Ethereum address to check if it is manager.
Returns
This method returns a Promise which resolves with true if the address is manager of the fund, otherwise it returns false.

Is main manager query

A query method that checks if the address is the main manager of the fund.
JavaScript & Node
1
const result = await fund.query.isMainManager("0xe5062E38DA29697cb122aAc70320a5847DD83960");
Copied!
Method parameters
address required string
Ethereum address to check if it is main manager.
Returns
This method returns a Promise which resolves with true if the address is main manager of the fund, otherwise it returns false.
Last modified 1yr ago