Search
K

Entity

Entity contract inherited by Org and Fund contracts (and all future kinds of Entities).

State Variables

registry

The base registry to which the entity is connected.
Registry public registry;

manager

The entity's manager.
address public manager;

baseToken

ERC20 public baseToken;

balance

The current balance for the entity, denominated in the base token's units.
uint256 public balance;

ETH_PLACEHOLDER

Placeholder address used in swapping method to denote usage of ETH instead of a token.
address public constant ETH_PLACEHOLDER = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

Functions

requiresManager

Modifier for methods that require auth and that the manager can access.
Uses the same condition as requiresAuth but with added manager access.
modifier requiresManager();

entityType

Each entity will implement this function to allow a caller to interrogate what kind of entity it is.
function entityType() public pure virtual returns (uint8);

__initEntity

One time method to be called at deployment to configure the contract. Required so Entity contracts can be deployed as minimal proxies (clones).
function __initEntity(Registry _registry, address _manager) internal;
Parameters
Name
Type
Description
_registry
Registry
The registry to host the Entity.
_manager
address
The address of the Entity's manager.

setManager

Set a new manager for this entity.
Callable by current manager or permissioned role.
function setManager(address _manager) external virtual requiresManager;
Parameters
Name
Type
Description
_manager
address
Address of new manager.
Receives a donated amount of base tokens to be added to the entity's balance. Transfers default fee to treasury.
Reverts if the donation fee percentage is larger than 100% (equal to 1e4 when represented as a zoc).
Reverts if the token transfer fails.
function donate(uint256 _amount) external virtual;
Parameters
Name
Type
Description
_amount
uint256
Amount donated in base token.

donateWithOverrides

Receives a donated amount of base tokens to be added to the entity's balance. Transfers default or overridden fee to treasury.
Reverts if the donation fee percentage is larger than 100% (equal to 1e4 when represented as a zoc).
Reverts if the token transfer fails.
function donateWithOverrides(uint256 _amount) external virtual;
Parameters
Name
Type
Description
_amount
uint256
Amount donated in base token.

donateWithAdminOverrides

Receives a donated amount of base tokens to be added to the entity's balance. This method can be called by permissioned actors to make a donation with a manually specified fee.
Reverts if the transfer fee percentage is larger than 100% (equal to 1e4 when represented as a zoc).
Reverts if the token transfer fails.
Reverts with Unauthorized if the msg.sender is not a privileged role.
function donateWithAdminOverrides(uint256 _amount, uint32 _feeOverride) external virtual requiresAuth;
Parameters
Name
Type
Description
_amount
uint256
Amount donated in base token.
_feeOverride
uint32
Fee percentage as zoc.

_donateWithFeeMultiplier

Receives a donated amount of base tokens to be added to the entity's balance. Transfers fee calculated by fee multiplier to treasury.
Reverts if the donation fee percentage is larger than 100% (equal to 1e4 when represented as a zoc).
Reverts if the token transfer fails.
function _donateWithFeeMultiplier(uint256 _amount, uint32 _feeMultiplier) internal virtual;
Parameters
Name
Type
Description
_amount
uint256
Amount donated in base token.
_feeMultiplier
uint32
Value indicating the percentage of the Endaoment donation fee to go to the Endaoment treasury.

swapAndDonate

Receive a donated amount of ETH or ERC20 tokens, swaps them to base tokens, and adds the output to the entity's balance. Fee calculated using default rate and sent to treasury.
function swapAndDonate(ISwapWrapper _swapWrapper, address _tokenIn, uint256 _amountIn, bytes calldata _data)
external
payable
virtual;
Parameters
Name
Type
Description
_swapWrapper
ISwapWrapper
The swap wrapper to use for the donation. Must be whitelisted on the Registry.
_tokenIn
address
The address of the ERC20 token to swap and donate, or ETH_PLACEHOLDER if donating ETH.
_amountIn
uint256
The amount of tokens or ETH being swapped and donated.
_data
bytes
Additional call data required by the ISwapWrapper being used.

swapAndDonateWithOverrides

Receive a donated amount of ETH or ERC20 tokens, swaps them to base tokens, and adds the output to the entity's balance. Fee calculated using override rate and sent to treasury.
function swapAndDonateWithOverrides(
ISwapWrapper _swapWrapper,
address _tokenIn,
uint256 _amountIn,
bytes calldata _data
) external payable virtual;
Parameters
Name
Type
Description
_swapWrapper
ISwapWrapper
The swap wrapper to use for the donation. Must be whitelisted on the Registry.
_tokenIn
address
The address of the ERC20 token to swap and donate, or ETH_PLACEHOLDER if donating ETH.
_amountIn
uint256
The amount of tokens or ETH being swapped and donated.
_data
bytes
Additional call data required by the ISwapWrapper being used.

_swapAndDonateWithFeeMultiplier

Internal helper implementing swap and donate functionality for any fee multiplier provided.
function _swapAndDonateWithFeeMultiplier(
ISwapWrapper _swapWrapper,
address _tokenIn,
uint256 _amountIn,
bytes calldata _data,
uint32 _feeMultiplier
) internal virtual nonReentrant;

transferToEntity

Transfers an amount of base tokens from one entity to another. Transfers default fee to treasury.
Reverts if the entity is inactive or if the token transfer fails.
Reverts if the transfer fee percentage is larger than 100% (equal to 1e4 when represented as a zoc).
Reverts with Unauthorized if the msg.sender is not the entity manager or a privileged role.
Renamed from transfer to distinguish from ERC20 transfer in 3rd party tools.
function transferToEntity(Entity _to, uint256 _amount) external virtual requiresManager;
Parameters
Name
Type
Description
_to
Entity
The entity to receive the tokens.
_amount
uint256
Contains the amount being donated (denominated in the base token's units).

transferToEntityWithOverrides

Transfers an amount of base tokens from one entity to another. Transfers default or overridden fee to treasury.
Reverts if the entity is inactive or if the token transfer fails.
Reverts if the transfer fee percentage is larger than 100% (equal to 1e4 when represented as a zoc).
Reverts with Unauthorized if the msg.sender is not the entity manager or a privileged role.
function transferToEntityWithOverrides(Entity _to, uint256 _amount) external virtual requiresManager;
Parameters
Name
Type
Description
_to
Entity
The entity to receive the tokens.
_amount
uint256
Contains the amount being donated (denominated in the base token's units).

transferToEntityWithAdminOverrides

Transfers an amount of base tokens from one entity to another. Transfers fee specified by a privileged role.
Reverts if the entity is inactive or if the token transfer fails.
Reverts if the transfer fee percentage is larger than 100% (equal to 1e4 when represented as a zoc).
Reverts with Unauthorized if the msg.sender is not a privileged role.
function transferToEntityWithAdminOverrides(Entity _to, uint256 _amount, uint32 _feeOverride)
external
virtual
requiresAuth;
Parameters
Name
Type
Description
_to
Entity
The entity to receive the tokens.
_amount
uint256
Contains the amount being donated (denominated in the base token's units).
_feeOverride
uint32
Admin override configured by an Admin

_transferWithFeeMultiplier

Transfers an amount of base tokens from one entity to another. Transfers fee calculated by fee multiplier to treasury.
Reverts with 'Inactive' if the entity sending the transfer or the entity receiving the transfer is inactive.
Reverts if the transfer fee percentage is larger than 100% (equal to 1e4 when represented as a zoc).
Reverts with Unauthorized if the msg.sender is not the entity manager or a privileged role.
Reverts if the token transfer fails.
function _transferWithFeeMultiplier(Entity _to, uint256 _amount, uint32 _feeMultiplier) internal virtual;
Parameters
Name
Type
Description
_to
Entity
The entity to receive the tokens.
_amount
uint256
Contains the amount being donated (denominated in the base token's units).
_feeMultiplier
uint32
Value indicating the percentage of the Endaoment donation fee to go to the Endaoment treasury.

receiveTransfer

Updates the receiving entity balance on a transfer.
This function is external, but is restricted such that it can only be called by other entities.
function receiveTransfer(uint256 _transferAmount) external virtual;
Parameters
Name
Type
Description
_transferAmount
uint256
The amount being received on the transfer.

portfolioDeposit

Deposits an amount of Entity's baseToken into an Endaoment-approved Portfolio.
function portfolioDeposit(Portfolio _portfolio, uint256 _amount, bytes calldata _data)
external
virtual
requiresManager
returns (uint256);
Parameters
Name
Type
Description
_portfolio
Portfolio
An Endaoment-approved portfolio.
_amount
uint256
Amount of baseToken to deposit into the portfolio.
_data
bytes
Data required by a portfolio to deposit.
Returns
Name
Type
Description
<none>
uint256
_shares Amount of portfolio share tokens Entity received as a result of this deposit.

portfolioRedeem

Redeems an amount of Entity's portfolio shares for an amount of baseToken.
function portfolioRedeem(Portfolio _portfolio, uint256 _shares, bytes calldata _data)
external
virtual
requiresManager
returns (uint256);
Parameters
Name
Type
Description
_portfolio
Portfolio
An Endaoment-approved portfolio.
_shares
uint256
Amount of share tokens to redeem.
_data
bytes
Data required by a portfolio to redeem.
Returns
Name
Type
Description
<none>
uint256
_received Amount of baseToken Entity received as a result of this redemption.

reconcileBalance

This method should be called to reconcile the Entity's internal baseToken accounting with the baseToken contract's accounting. There are a 2 situations where calling this method is appropriate:
  1. 1.
    To process amounts of baseToken that arrived at this Entity through methods besides Entity:donate or Entity:transfer. For example, if this Entity receives a normal ERC20 transfer of baseToken, the amount received will be unavailable for Entity use until this method is called to adjust the balance and process fees. OrgFundFactory.sol:_donate makes use of this method to do this as well.
  2. 2.
    Unusually, the Entity's perspective of balance could be lower than baseToken.balanceOf(this). This could happen if Entity:callAsEntity is used to transfer baseToken. In this case, this method provides a way of correcting the Entity's internal balance.
function reconcileBalance() external virtual;

swapAndReconcileBalance

Takes stray tokens or ETH sent directly to this Entity, swaps them for base token, then adds them to the Entity's balance after paying the appropriate fee to the treasury.
function swapAndReconcileBalance(ISwapWrapper _swapWrapper, address _tokenIn, uint256 _amountIn, bytes calldata _data)
external
virtual
nonReentrant
requiresManager;
Parameters
Name
Type
Description
_swapWrapper
ISwapWrapper
The swap wrapper to use to convert the assets. Must be whitelisted on the Registry.
_tokenIn
address
The address of the ERC20 token to swap, or ETH_PLACEHOLDER if ETH.
_amountIn
uint256
The amount of tokens or ETH being swapped and added to the balance.
_data
bytes
Additional call data required by the ISwapWrapper being used.

callAsEntity

Permissioned method that allows Endaoment admin to make arbitrary calls acting as this Entity.
function callAsEntity(address _target, uint256 _value, bytes memory _data)
external
payable
virtual
requiresAuth
returns (bytes memory);
Parameters
Name
Type
Description
_target
address
The address to which the call will be made.
_value
uint256
The ETH value that should be forwarded with the call.
_data
bytes
The calldata that will be sent with the call.
Returns
Name
Type
Description
<none>
bytes
_return The data returned by the call.

payout

Pays out an amount of base tokens from the entity to an address. Transfers the fee calculated by the default fee multiplier to the treasury.
Reverts with Unauthorized if the msg.sender is not a privileged role.
Reverts if the fee percentage is larger than 100% (equal to 1e4 when represented as a zoc).
Reverts if the token transfer fails.
function payout(address _to, uint256 _amount) external virtual requiresAuth;
Parameters
Name
Type
Description
_to
address
The address to receive the tokens.
_amount
uint256
Amount donated in base token.

payoutWithOverrides

Pays out an amount of base tokens from the entity to an address. Transfers the fee calculated by the default fee multiplier to the treasury.
Reverts with Unauthorized if the msg.sender is not a privileged role.
Reverts if the fee percentage is larger than 100% (equal to 1e4 when represented as a zoc).
Reverts if the token transfer fails.
function payoutWithOverrides(address _to, uint256 _amount) external virtual requiresAuth;
Parameters
Name
Type
Description
_to
address
_amount
uint256
Amount donated in base token.

payoutWithAdminOverrides

Pays out an amount of base tokens from the entity to an address. Transfers fee specified by a privileged role.
Reverts with Unauthorized if the msg.sender is not a privileged role.
Reverts if the fee percentage is larger than 100% (equal to 1e4 when represented as a zoc).
Reverts if the token transfer fails.
function payoutWithAdminOverrides(address _to, uint256 _amount, uint32 _feeOverride) external virtual requiresAuth;
Parameters
Name
Type
Description
_to
address
_amount
uint256
Amount donated in base token.
_feeOverride
uint32
Payout override configured by an Admin

_payoutWithFeeMultiplier

Pays out an amount of base tokens from the entity to an address. Transfers the fee calculated by fee multiplier to the treasury.
Reverts if the token transfer fails.
Reverts if the fee percentage is larger than 100% (equal to 1e4 when represented as a zoc).
function _payoutWithFeeMultiplier(address _to, uint256 _amount, uint32 _feeMultiplier) internal virtual;
Parameters
Name
Type
Description
_to
address
The address to receive the tokens.
_amount
uint256
Contains the amount being paid out (denominated in the base token's units).
_feeMultiplier
uint32
Value indicating the percentage of the Endaoment fee to go to the Endaoment treasury.

_calculateFee

Internal helper method to calculate the fee on a base token amount for a given fee multiplier.
function _calculateFee(uint256 _amount, uint256 _feeMultiplier)
internal
pure
virtual
returns (uint256 _netAmount, uint256 _fee);

receive

receive() external payable virtual;

Events

EntityManagerSet

Emitted when manager is set.
event EntityManagerSet(address indexed oldManager, address indexed newManager);

EntityDonationReceived

Emitted when a donation is made.
event EntityDonationReceived(
address indexed from,
address indexed to,
address indexed tokenIn,
uint256 amountIn,
uint256 amountReceived,
uint256 amountFee
);

EntityValuePaidOut

Emitted when a payout is made from an entity.
event EntityValuePaidOut(address indexed from, address indexed to, uint256 amountSent, uint256 amountFee);

EntityValueTransferred

Emitted when a transfer is made between entities.
event EntityValueTransferred(address indexed from, address indexed to, uint256 amountReceived, uint256 amountFee);

EntityBalanceReconciled

Emitted when a base token reconciliation completes.
event EntityBalanceReconciled(address indexed entity, uint256 amountReceived, uint256 amountFee);

EntityBalanceCorrected

Emitted when a base token balance is used to correct the internal contract balance.
event EntityBalanceCorrected(address indexed entity, uint256 newBalance);

EntityDeposit

Emitted when a portfolio deposit is made.
event EntityDeposit(address indexed portfolio, uint256 baseTokenDeposited, uint256 sharesReceived);

EntityRedeem

Emitted when a portfolio share redemption is made.
event EntityRedeem(address indexed portfolio, uint256 sharesRedeemed, uint256 baseTokenReceived);

EntityEthReceived

Emitted when ether is received.
event EntityEthReceived(address indexed sender, uint256 amount);