Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
shuffle keysAsUint32 out of Lib to IF Contract internal function to c…
Browse files Browse the repository at this point in the history
…ontrol where it is called
  • Loading branch information
Andrey authored and Andrey committed Aug 1, 2023
1 parent 51f75bb commit 0c57010
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
19 changes: 16 additions & 3 deletions contracts/core/index-fund/IndexFund.sol
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ contract IndexFund is IIndexFund, Storage, OwnableUpgradeable, ReentrancyGuard,
state.EndowmentsByFund[fundId].keys.length <= MAX_ENDOWMENT_MEMBERS,
"Fund endowment members exceeds upper limit"
);
emit MembersUpdated(fundId, IterableMapping.keysAsUint32(state.EndowmentsByFund[fundId]));
emit MembersUpdated(fundId, keysAsUint32(state.EndowmentsByFund[fundId]));
}

/**
Expand Down Expand Up @@ -407,7 +407,7 @@ contract IndexFund is IIndexFund, Storage, OwnableUpgradeable, ReentrancyGuard,
id: state.Funds[fundId].id,
name: state.Funds[fundId].name,
description: state.Funds[fundId].description,
endowments: IterableMapping.keysAsUint32(state.EndowmentsByFund[fundId]),
endowments: keysAsUint32(state.EndowmentsByFund[fundId]),
splitToLiquid: state.Funds[fundId].splitToLiquid,
expiryTime: state.Funds[fundId].expiryTime
});
Expand All @@ -434,7 +434,7 @@ contract IndexFund is IIndexFund, Storage, OwnableUpgradeable, ReentrancyGuard,
id: state.Funds[state.activeFund].id,
name: state.Funds[state.activeFund].name,
description: state.Funds[state.activeFund].description,
endowments: IterableMapping.keysAsUint32(state.EndowmentsByFund[state.activeFund]),
endowments: keysAsUint32(state.EndowmentsByFund[state.activeFund]),
splitToLiquid: state.Funds[state.activeFund].splitToLiquid,
expiryTime: state.Funds[state.activeFund].expiryTime
});
Expand Down Expand Up @@ -547,4 +547,17 @@ contract IndexFund is IIndexFund, Storage, OwnableUpgradeable, ReentrancyGuard,
return state.rotatingFunds[index + 1];
}
}

/**
* @dev Converts a Map's keys from a Uint256 Array to Uint32 Array
* @param map Map
* @return keys32 Map's keys as a Uint32 Array
*/
function keysAsUint32(IterableMapping.Map storage map) internal view returns (uint32[] memory) {
uint32[] memory keys32 = new uint32[](map.keys.length);
for (uint256 i = 0; i < map.keys.length; i++) {
keys32[i] = uint32(map.keys[i]);
}
return keys32;
}
}
13 changes: 0 additions & 13 deletions contracts/lib/IterableMapping.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,4 @@ contract IterableMapping {
map.keys[index] = lastKey;
map.keys.pop();
}

/**
* @dev Converts a Map's keys from a Uint256 Array to Uint32 Array
* @param map Map
* @return keys32 Map's keys as a Uint32 Array
*/
function keysAsUint32(Map storage map) internal view returns (uint32[] memory) {
uint32[] memory keys32 = new uint32[](map.keys.length);
for (uint256 i = 0; i < map.keys.length; i++) {
keys32[i] = uint32(map.keys[i]);
}
return keys32;
}
}

0 comments on commit 0c57010

Please sign in to comment.