Skip to content

Commit 1f1182e

Browse files
committed
Use calldata instead of memory for external function array parameters
1 parent 01be197 commit 1f1182e

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/helpers/VedaAdapter.sol

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ contract VedaAdapter is Ownable2Step {
199199
* `ERC20TransferAmountEnforcer` as its first caveat (`caveats[0]`), capped to exactly the intended
200200
* deposit amount, to prevent over-spending or replay.
201201
*/
202-
function depositByDelegation(Delegation[] memory _delegations, uint256 _minimumMint) external {
202+
function depositByDelegation(Delegation[] calldata _delegations, uint256 _minimumMint) external {
203203
_executeDepositByDelegation(_delegations, _minimumMint);
204204
}
205205

@@ -212,12 +212,12 @@ contract VedaAdapter is Ownable2Step {
212212
* `ERC20TransferAmountEnforcer` as its first caveat (`caveats[0]`), capped to exactly the intended
213213
* deposit amount, to prevent over-spending or replay.
214214
*/
215-
function depositByDelegationBatch(DepositParams[] memory _depositStreams) external {
215+
function depositByDelegationBatch(DepositParams[] calldata _depositStreams) external {
216216
uint256 streamsLength_ = _depositStreams.length;
217217
if (streamsLength_ == 0) revert InvalidBatchLength();
218218

219219
for (uint256 i = 0; i < streamsLength_;) {
220-
DepositParams memory params_ = _depositStreams[i];
220+
DepositParams calldata params_ = _depositStreams[i];
221221
_executeDepositByDelegation(params_.delegations, params_.minimumMint);
222222
unchecked {
223223
++i;
@@ -245,7 +245,7 @@ contract VedaAdapter is Ownable2Step {
245245
* `ERC20TransferAmountEnforcer` as its first caveat (`caveats[0]`), capped to exactly `_shareAmount`,
246246
* to prevent over-spending or replay.
247247
*/
248-
function withdrawByDelegation(Delegation[] memory _delegations, address _token, uint256 _minimumAssets) external {
248+
function withdrawByDelegation(Delegation[] calldata _delegations, address _token, uint256 _minimumAssets) external {
249249
_executeWithdrawByDelegation(_delegations, _token, _minimumAssets);
250250
}
251251

@@ -258,12 +258,12 @@ contract VedaAdapter is Ownable2Step {
258258
* `ERC20TransferAmountEnforcer` as its first caveat (`caveats[0]`), capped to exactly the intended
259259
* share amount, to prevent over-spending or replay.
260260
*/
261-
function withdrawByDelegationBatch(WithdrawParams[] memory _withdrawStreams) external {
261+
function withdrawByDelegationBatch(WithdrawParams[] calldata _withdrawStreams) external {
262262
uint256 streamsLength_ = _withdrawStreams.length;
263263
if (streamsLength_ == 0) revert InvalidBatchLength();
264264

265265
for (uint256 i = 0; i < streamsLength_;) {
266-
WithdrawParams memory params_ = _withdrawStreams[i];
266+
WithdrawParams calldata params_ = _withdrawStreams[i];
267267
_executeWithdrawByDelegation(params_.delegations, params_.token, params_.minimumAssets);
268268
unchecked {
269269
++i;
@@ -307,19 +307,16 @@ contract VedaAdapter is Ownable2Step {
307307
}
308308

309309
/**
310-
* @notice Parses ERC20TransferAmountEnforcer terms from memory bytes
310+
* @notice Parses ERC20TransferAmountEnforcer terms from calldata bytes
311311
* @dev Terms format: abi.encodePacked(address token, uint256 amount) = 52 bytes.
312-
* Slice syntax is only available for calldata; assembly is used to read from memory bytes.
313312
* @param _terms The raw terms bytes from a caveat
314313
* @return token_ The token address encoded in the first 20 bytes
315314
* @return amount_ The uint256 amount encoded in bytes 20-51
316315
*/
317-
function _parseERC20TransferTerms(bytes memory _terms) private pure returns (address token_, uint256 amount_) {
316+
function _parseERC20TransferTerms(bytes calldata _terms) private pure returns (address token_, uint256 amount_) {
318317
if (_terms.length < 52) revert InvalidTermsLength();
319-
assembly {
320-
token_ := shr(96, mload(add(_terms, 32)))
321-
amount_ := mload(add(_terms, 52))
322-
}
318+
token_ = address(bytes20(_terms[0:20]));
319+
amount_ = uint256(bytes32(_terms[20:52]));
323320
}
324321

325322
/**
@@ -329,7 +326,7 @@ contract VedaAdapter is Ownable2Step {
329326
* @param _delegations Delegation chain, sorted leaf to root
330327
* @param _minimumMint Minimum vault shares expected (sanity-check bound)
331328
*/
332-
function _executeDepositByDelegation(Delegation[] memory _delegations, uint256 _minimumMint) internal {
329+
function _executeDepositByDelegation(Delegation[] calldata _delegations, uint256 _minimumMint) internal {
333330
uint256 length_ = _delegations.length;
334331
if (length_ < 2) revert InvalidDelegationsLength();
335332

@@ -366,7 +363,7 @@ contract VedaAdapter is Ownable2Step {
366363
* @param _token Underlying output token to receive from the vault (differs from the share token in the caveat)
367364
* @param _minimumAssets Minimum underlying assets expected (sanity-check bound)
368365
*/
369-
function _executeWithdrawByDelegation(Delegation[] memory _delegations, address _token, uint256 _minimumAssets) internal {
366+
function _executeWithdrawByDelegation(Delegation[] calldata _delegations, address _token, uint256 _minimumAssets) internal {
370367
uint256 length_ = _delegations.length;
371368
if (length_ < 2) revert InvalidDelegationsLength();
372369
if (_token == address(0)) revert InvalidZeroAddress();

0 commit comments

Comments
 (0)