Portfolios

A portfolio is a smart contract that can hold any asset and execute Defire's operations. Portfolios have owners and managers that can be added or removed.

Portfolios' owners are the only accounts to whom the assets can be withdrawn. There is a main owner who can add and remove other owners. Even though owners can execute operations, never use an owner account to operate. It is recommended to keep owners accounts secure, for example, in a hardware wallet, and to operate with managers.

Portfolios' 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.

Portfolios are secure because even if any manager account (including main manager account) is hacked, the assets cannot be stolen because they can only be withdrawn to owner's accounts.

Initialization

Create a portfolio action

An action method to create a new portfolio.

JavaScript & Node
JavaScript & Node
const portfolio = await defire.actions.createPortfolio({
owners: ["0xF335fD8CEE75f7759b2fb05a9B3B8A9c85bb1dA3"],
managers: ["0xeA51f872dcaA7f4C3895092B95004a64AE680004"]
});

Create object param fields

owners required array of strings

List of portfolio's owners. There must be at least one owner. First owner will be the main owner.

managers requiredarray of strings

List of portfolio'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 portfolio 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 an portfolio object.

Get a portfolio query

A query method to get an existing portfolio.

JavaScript & Node
JavaScript & Node
const portfolio = await defire.query.getPortfolio("0x3915185D3a079d841B6b6D8dAa7E9067e0A05380");

Method parameters

address required string

Smart contract address of the portfolio.

Returns

This method returns a Promise which resolves with an portfolio object.

Portfolio object

It contains the information, query and action methods about a specific portfolio.

Object fields

address string

Smart contract address of the portfolio

Assets query

A query to get the list of assets that the portfolio holds.

JavaScript & Node
JavaScript & Node
const assets = await portfolio.query.getAssets();

Returns

This method returns a Promise which resolves with anarray of string addresses of assets that the portfolio holds.

Asset balance query

A query to check portfolio balance of an asset.

JavaScript & Node
JavaScript & Node
const balance = await portfolio.query.balance(defire.Assets.DAI);

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 portfolio holds an asset.

JavaScript & Node
JavaScript & Node
const result = await portfolio.query.hasAsset(defire.Assets.DAI);

Method parameters

address required string

Smart contract address of the asset.

Returns

This method returns a Promise which resolves with true if the portfolio has the asset or false if not.

Execute single operation action

An action method to execute one DeFi operation from the portfolio.

JavaScript & Node
JavaScript & Node
const result = await portfolio.actions.execute(operation);

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 portfolio.

JavaScript & Node
JavaScript & Node
const result = await portfolio.actions.execute(
[operation1, operation2, operation3]
);

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.

Withdraw assets action

An action method to withdraw portfolio assets to the owner.

JavaScript & Node
JavaScript & Node
const result = await portfolio.actions.withdraw(
"0xF335fD8CEE75f7759b2fb05a9B3B8A9c85bb1dA3",
[{
asset: defire.Assets.DAI,
amount: "5000000000000000000" //5 DAI
},
{
asset: defire.Assets.ETH,
amount: "1500000000000000000" //1.5 ETH
}]
);

Method parameters

to required string

Address of an owner of the portfolio.

assets required array of object :

  • asset required string (Address of the asset)

  • amount required string | number | JSBI (Amount of the asset to withdraw in wei format)

List of each asset and amounts that will be withdrawn

Returns

This method returns a Promise which resolves with true if the assets where withdrawn successfully or throws an error if it failed.

Operate & withdraw assets action

An action method to execute multiple DeFi operations from the portfolio and then withdraw its assets to the owner.

JavaScript & Node
JavaScript & Node
const result = await portfolio.actions.operateAndWithdraw(
[
operation1,
operation2,
operation3
],
to: "0xF335fD8CEE75f7759b2fb05a9B3B8A9c85bb1dA3",
[{
asset: defire.Assets.DAI,
amount: "5000000000000000000" //5 DAI
},
{
asset: defire.Assets.ETH
amount: "1500000000000000000" //1.5 ETH
}]
);

Method parameters

operations required array of operation object

DeFi operations to be executed.

to required string

Address of an owner of the portfolio.

assets required array of object :

  • asset required string (Address of the asset)

  • amount required string | number | JSBI (Amount of the asset to withdraw in wei format)

List of each asset and amounts that will be withdrawn

Returns

This method returns a Promise which resolves with true if the operations were executed and the assets withdrawn successfully or throws an error if it failed.

Add owner action

An action method to add a new owner to the portfolio.

JavaScript & Node
JavaScript & Node
const result = await portfolio.actions.addOwner("0xe5eE35Aa75698eADdF5BAab64cf7C77Dd1111a4E");

Method parameters

address required string

New owner address.

Returns

This method returns a Promise which resolves with true if the owner was added successfully or throws an error if it failed.

Remove owner action

An action method to remove an owner from the portfolio.

JavaScript & Node
JavaScript & Node
const result = await portfolio.actions.removeOwner("0xe5eE35Aa75698eADdF5BAab64cf7C77Dd1111a4E");

Method parameters

address required string

Address of the owner to be removed.

Returns

This method returns a Promise which resolves with true if the owner was removed successfully or throws an error if it failed.

Is owner query

A query method that checks if the address is an owner of the portfolio.

JavaScript & Node
JavaScript & Node
const result = await portfolio.query.isOwner("0xe5eE35Aa75698eADdF5BAab64cf7C77Dd1111a4E");

Method parameters

address required string

Ethereum address to check if it is owner.

Returns

This method returns a Promise which resolves with true if the address is owner of the portfolio, otherwise it returns false.

Is main owner query

A query method that checks if the address is the main owner of the portfolio.

JavaScript & Node
JavaScript & Node
const result = await portfolio.query.isMainOwner("0xe5eE35Aa75698eADdF5BAab64cf7C77Dd1111a4E");

Method parameters

address required string

Ethereum address to check if it is main owner.

Returns

This method returns a Promise which resolves with true if the address is main owner of the portfolio, otherwise it returns false.

Add manager action

An action method to add a new manager to the portfolio.

JavaScript & Node
JavaScript & Node
const result = await portfolio.actions.addManager("0x9038afa398563815cc26b9ec5Ecd3b8069cd9507");

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 portfolio.

JavaScript & Node
JavaScript & Node
const result = await portfolio.actions.removeManager("0x9038afa398563815cc26b9ec5Ecd3b8069cd9507");

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 portfolio.

JavaScript & Node
JavaScript & Node
const result = await portfolio.query.isManager("0x9038afa398563815cc26b9ec5Ecd3b8069cd9507");

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 portfolio, otherwise it returns false.

Is main manager query

A query method that checks if the address is the main manager of the portfolio.

JavaScript & Node
JavaScript & Node
const result = await portfolio.query.isMainManager("0x9038afa398563815cc26b9ec5Ecd3b8069cd9507");

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 portfolio, otherwise it returns false.