Disclaimer: I’ve been told by readers that I sometimes have spelling mistakes and poor grammar - I’m not going to fix, that time will be spent reading more code.
Hey everyone welcome back to waints blog. Today we’re walking through the Manager contracts for LooksRare:
CurrencyManager ----- ExecutionManager
CurrencyManager is all about which currencies are available on LooksRare, its a pretty quick contract.
First thing to note is the imports -- Ownable and EnumerableSet. We’re aware of what Ownable does, lets someone be the owner of a contract. EnumerableSet is an interesting one though.
EnumerableSet gives us a struct like element that has two internal variables: _values, and indexes*.* values is a list of Bytes, and _indexes is a mapping from bytes to integers. So basically what this gives us is the capability to store items in a list, and know where those items are located in the list. The benefit of this is O(1) time for accessing, adding, removing, and validating items -- so using EnumerableSet is much much more efficient than using a list. In the CurrencyManager we’ll use this to store addresses of currencies so that it’s efficient to access and edit our list of currencies. Now lets checkout the interface quick.
The interface outlines 5 functions for us: (function (input))
addCurrency (address) - Add a currency to the list
removeCurrency (address) - Remove a currency from the list
isCurrencyWhitelisted (address) - Returns true if the currency is in the whitelist
viewWhitelistedCurrencies (integer, integer) - Returns whitelisted currencies for the input parameters
viewCountWhiteListedCurrencies () - Returns how many currencies are in the whitelist
So basically manage what currencies are available - we should expect these functions to be defined in CurrencyManager.sol. Lets go ..
contract CurrencyManager is ICurrencyManager, Ownable {
using EnumerableSet for EnumerableSet.AddressSet;
This is 90% of the functionality of the contract - an EnumerableSet full of addresses. Using this as a base the contract adds two events (CurrencyRemoved, CurrencyWhitelisted) on top of it and wraps the add/remove functionality of the sets in functions.

We then have two simple functions to check if the currency is whitelisted, and return the number of currencies in the set.
The last function is one that returns all the whitelisted currencies based on the two input parameters:
cursor → Index to start listing currencies at
size → Number of currencies to display
Whats weird about this function is that the size input is immediately set to a new variable - length.
uint256 length = size;
I honestly dont know why they did this. There may be some integer wrap that comes with re-assigning it that I dont know about, but if there is nothing then this is a waste of gas. I’m guessing it has something to do with the next two lines but I’m not sure:
if (length > _whitelistedCurrencies.length() - cursor) {
length = _whitelistedCurrencies.length() - cursor;
}
This is saying if the number of items requested in the input is larger than the number of items remaining in the set starting at the cursor input location, we will use the number of items remaining in the set as the new length.
Next the contract copies all the items from the cursor to set length and returns that array along with the length of the set. This last return is a little weird for me, if they’re returning the length of the OG set they could have done this differently, and if they’re trying to return the length of the new set returned its not correct. Maybe theres something I’m missing here, guess we’ll have to keep reading contracts ..

Aight im done with this one lets move on to ExecutionManager.sol
Damn this one is almost identical ..
The only real difference is instead of currencies, we’re dealing with strategies we discussed earlier. So I guess theres not much more to learn here, time to go deeper
