IBosonFundsHandler
View Source: contracts/interfaces/handlers/IBosonFundsHandler.sol
↗ Extends: IBosonFundsEvents, IBosonFundsLibEvents
IBosonFundsHandler
Handles custody and withdrawal of buyer and seller funds within the protocol.
The ERC-165 identifier for this interface is: 0x2f4a64d7
Functions
- depositFunds(uint256 _sellerId, address _tokenAddress, uint256 _amount)
- withdrawFunds(uint256 _entityId, address[] _tokenList, uint256[] _tokenAmounts)
- withdrawProtocolFees(address[] _tokenList, uint256[] _tokenAmounts)
- getTokenList(uint256 _entityId)
- getTokenListPaginated(uint256 _entityId, uint256 _limit, uint256 _offset)
- getAllAvailableFunds(uint256 _entityId)
- getAvailableFunds(uint256 _entityId, address[] _tokenList)
depositFunds
Receives funds from the caller, maps funds to the seller id and stores them so they can be used during the commitToOffer.
Emits FundsDeposited event if successful.
Reverts if:
- The funds region of protocol is paused
- Seller id does not exist
- It receives some native currency (e.g. ETH), but token address is not zero
- It receives some native currency (e.g. ETH), and the amount does not match msg.value
- Contract at token address does not support ERC20 function transferFrom
- Calling transferFrom on token fails for some reason (e.g. protocol is not approved to transfer)
- Received ERC20 token amount differs from the expected value
function depositFunds(uint256 _sellerId,
address _tokenAddress,
uint256 _amount)
external
payable
Arguments
Name | Type | Description |
---|---|---|
_sellerId | uint256 | id of the seller that will be credited |
_tokenAddress | address | contract address of token that is being deposited (0 for native currency) |
_amount | uint256 | amount to be credited |
withdrawFunds
Withdraws the specified funds. Can be called for seller, buyer or agent.
Emits FundsWithdrawn event if successful.
Reverts if:
- The funds region of protocol is paused
- Caller is not associated with the entity id
- Token list length does not match amount list length
- Caller tries to withdraw more that they have in available funds
- There is nothing to withdraw
- Transfer of funds is not successful
function withdrawFunds(uint256 _entityId,
address[] _tokenList,
uint256[] _tokenAmounts)
external
Arguments
Name | Type | Description |
---|---|---|
_entityId | uint256 | id of entity for which funds should be withdrawn |
_tokenList | address[] | list of contract addresses of tokens that are being withdrawn |
_tokenAmounts | uint256[] | list of amounts to be withdrawn, corresponding to tokens in tokenList |
withdrawProtocolFees
Withdraws the protocol fees.Can only be called by the FEE_COLLECTOR role.
Emits FundsWithdrawn event if successful.
Reverts if:
- The funds region of protocol is paused
- Caller does not have the FEE_COLLECTOR role
- Token list length does not match amount list length
- Caller tries to withdraw more that they have in available funds
- There is nothing to withdraw
- Transfer of funds is not successful
function withdrawProtocolFees(address[] _tokenList,
uint256[] _tokenAmounts)
external
Arguments
Name | Type | Description |
---|---|---|
_tokenList | address[] | list of contract addresses of tokens that are being withdrawn |
_tokenAmounts | uint256[] | list of amounts to be withdrawn, corresponding to tokens in tokenList |
getTokenList
Returns list of addresses for which the entity has funds available.
If the list is too long, it can be retrieved in chunks by using getTokenListPaginated
and specifying _limit and _offset.
function getTokenList(uint256 _entityId)
external
view
returns(address[] tokenList)
Arguments
Name | Type | Description |
---|---|---|
_entityId | uint256 | id of entity for which availability of funds should be checked |
Returns
Name | Type | Description |
---|---|---|
tokenList | address[] | list of token addresses |
getTokenListPaginated
Returns list of addresses for which the entity has funds available.
function getTokenListPaginated(uint256 _entityId,
uint256 _limit,
uint256 _offset)
external
view
returns(address[] tokenList)
Arguments
Name | Type | Description |
---|---|---|
_entityId | uint256 | id of entity for which availability of funds should be checked |
_limit | uint256 | the maximum number of token addresses that should be returned starting from the index defined by _offset . If _offset + _limit exceeds total tokens, _limit is adjusted to return all remaining tokens. |
_offset | uint256 | the starting index from which to return token addresses. If _offset is greater than or equal to total tokens, an empty list is returned. |
Returns
Name | Type | Description |
---|---|---|
tokenList | address[] | list of token addresses |
getAllAvailableFunds
Returns the information about the funds that an entity can use as a sellerDeposit and/or withdraw from the protocol.
It tries to get information about all tokens that the entity has in availableFunds storage.
If the token list is too long, this call may run out of gas. In this case, the caller should use the function getAvailableFunds
and pass the token list.
function getAllAvailableFunds(uint256 _entityId)
external
view
returns(BosonTypes.Funds[] memory availableFunds)
Arguments
Name | Type | Description |
---|---|---|
_entityId | uint256 | id of entity for which availability of funds should be checked |
Returns
Name | Type | Description |
---|---|---|
availableFunds | BosonTypes.Funds[] | list of token addresses, token names and amount that can be used as a seller deposit or be withdrawn |
getAvailableFunds
Returns the information about the funds that an entity can use as a sellerDeposit and/or withdraw from the protocol.
To get a list of tokens that the entity has in availableFunds storage, use the function getTokenList
.
function getAvailableFunds(uint256 _entityId,
address[] _tokenList)
external
view
returns(BosonTypes.Funds[] memory availableFunds)
Arguments
Name | Type | Description |
---|---|---|
_entityId | uint256 | id of entity for which availability of funds should be checked |
_tokenList | address[] | list of tokens addresses to get available funds |
Returns
Name | Type | Description |
---|---|---|
availableFunds | BosonTypes.Funds[] | list of token addresses, token names and amount that can be used as a seller deposit or be withdrawn |