-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More flexible getAvailableFunds #698
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
489598b
attack
zajck 37b2a89
getAvailableFunds with bounded gas consumption
zajck aa6abe9
token list getters
zajck 7f04cf2
Merge branch 'main' into dos-getAvailableFunds
zajck 1f035a0
Merge branch 'main' into dos-getAvailableFunds
zajck d1b50d3
Merge branch 'main' into dos-getAvailableFunds
mischat fc5a8df
Review changes
anajuliabit f3d4f71
Merge branch 'main' into dos-getAvailableFunds
anajuliabit cf4348a
Merge branch 'main' into dos-getAvailableFunds
mischat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,24 +149,77 @@ contract FundsHandlerFacet is IBosonFundsHandler, ProtocolBase { | |
withdrawFundsInternal(protocolAddresses().treasury, 0, _tokenList, _tokenAmounts); | ||
} | ||
|
||
/** | ||
* @notice 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. | ||
* | ||
* @param _entityId - id of entity for which availability of funds should be checked | ||
* @return tokenList - list of token addresses | ||
*/ | ||
function getTokenList(uint256 _entityId) external view override returns (address[] memory tokenList) { | ||
return protocolLookups().tokenList[_entityId]; | ||
} | ||
|
||
/** | ||
* @notice Returns list of addresses for which the entity has funds available. | ||
* | ||
* @param _entityId - id of entity for which availability of funds should be checked | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add _limit and _offset parameters here |
||
* @param _limit - 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. | ||
* @param _offset - the starting index from which to return token addresses. If `_offset` is greater than or equal to total tokens, an empty list is returned. | ||
* @return tokenList - list of token addresses | ||
*/ | ||
function getTokenListPaginated( | ||
uint256 _entityId, | ||
uint256 _limit, | ||
uint256 _offset | ||
) external view override returns (address[] memory tokenList) { | ||
address[] storage tokens = protocolLookups().tokenList[_entityId]; | ||
|
||
if (_offset >= tokens.length) { | ||
return new address[](0); | ||
} else if (_offset + _limit > tokens.length) { | ||
_limit = tokens.length - _offset; | ||
} | ||
|
||
tokenList = new address[](_limit); | ||
|
||
for (uint i = 0; i < _limit; i++) { | ||
tokenList[i] = tokens[_offset++]; | ||
} | ||
|
||
return tokenList; | ||
} | ||
|
||
/** | ||
* @notice 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. | ||
* | ||
* @param _entityId - id of entity for which availability of funds should be checked | ||
* @return availableFunds - list of token addresses, token names and amount that can be used as a seller deposit or be withdrawn | ||
*/ | ||
function getAllAvailableFunds(uint256 _entityId) external view override returns (Funds[] memory availableFunds) { | ||
// get list of token addresses for the entity | ||
address[] memory tokenList = protocolLookups().tokenList[_entityId]; | ||
return getAvailableFunds(_entityId, tokenList); | ||
} | ||
|
||
/** | ||
* @notice 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`. | ||
* | ||
* @param _entityId - id of entity for which availability of funds should be checked | ||
* @param _tokenList - list of tokens addresses to get available funds | ||
* @return availableFunds - list of token addresses, token names and amount that can be used as a seller deposit or be withdrawn | ||
*/ | ||
function getAvailableFunds( | ||
uint256 _entityId, | ||
address[] calldata _tokenList | ||
) external view override returns (Funds[] memory availableFunds) { | ||
// Cache protocol lookups for reference | ||
ProtocolLib.ProtocolLookups storage lookups = protocolLookups(); | ||
|
||
address[] memory _tokenList | ||
) public view override returns (Funds[] memory availableFunds) { | ||
availableFunds = new Funds[](_tokenList.length); | ||
|
||
// Get entity's availableFunds storage pointer | ||
mapping(address => uint256) storage entityFunds = lookups.availableFunds[_entityId]; | ||
mapping(address => uint256) storage entityFunds = protocolLookups().availableFunds[_entityId]; | ||
|
||
for (uint256 i = 0; i < _tokenList.length; i++) { | ||
address tokenAddress = _tokenList[i]; | ||
|
@@ -176,8 +229,8 @@ contract FundsHandlerFacet is IBosonFundsHandler, ProtocolBase { | |
// If tokenAddress is 0, it represents the native currency | ||
tokenName = NATIVE_CURRENCY; | ||
} else { | ||
// Try to get token name | ||
try IERC20Metadata(tokenAddress).name() returns (string memory name) { | ||
// Try to get token name. Typically, name consumes less than 30,000 gas, but we leave some extra gas just in case | ||
try IERC20Metadata(tokenAddress).name{ gas: 40000 }() returns (string memory name) { | ||
tokenName = name; | ||
} catch { | ||
tokenName = TOKEN_NAME_UNSPECIFIED; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add _limit and _offset parameters here