My wife recently read the book "Let My Nation Descend" by Yosef Deutsch, which details the account of the sale of Yosef, culminating with the young nation of Israel journeying to Egypt. She shared a remarkable part of the story with me that I thought was both interesting and thought provoking.
On page 214, he brings down that during the years of famine, Yosef amassed an unbelievable amount of wealth from all of the different nations that came to him for food. According to Rav Aryeh Kaplan's assessment in his translation of the Yalkut Me'am Loez, in present day value, it would surpass the value of billions of dollars.
What did Yosef do with the money?
R' Deutsch brings down that half of the money was stored in the secure royal treasury. The second half was subdivided into three parts which were stored in different secret places. Hashem's promise to Avraham would be fulfilled with this wealth - the Jews would leave Egypt with fabulous riches.
Interestingly, he says that the three caches of money came from three different sources - Egyptian idol worshippers, criminals, and those who observed the Noachide commandments (lehavdil). When the Jews would leave Egypt many years later, Korach found one of the three sets of treasure, and that wealth was lost when Korach was swallowed by the ground after his rebellion. The second treasure would later be found by Antoninus of Rome, and the third treasure is reserved for the tzadikim in the times of Moshiach.
What is most remarkable to me in this whole description is that Yosef himself was the one who collected all of the money that the Jews left Egypt with at Yetzias Mitrayim, as well as the money that would be given to the righteous after the final Geulah. There is clearly something more to this than a cute side note to history.
It seems to me be'H, that here is another example of the role of Moshiach ben Yosef, and most interestingly, it is being performed by Yosef himself. One of the roles of Moshiach ben Yosef is that he is in charge of the physical welfare of the Jewish people, and he is also involved in the final rectification of wealth (see again Rebbe Nachman's story "The Master of Prayer").
What does this mean? I believe it is as follows.
To understand, we need to ask another question. Why is it important for the Jewish people to leave Egypt with tremendous wealth? Also, why is it important for the righteous to have this great wealth in the times of Moshiach?
I think the answer starts with the Rambam at the end of hilchos Melachim. There he says that the prophets and sages did not desire the days of Moshiach so that we would rule over the world and no longer be beholden to the other nations. Rather, it was so we could spend our time completely involved in the study of Torah, with no other worries or distractions.
What is the number one distraction from learning Torah (besides for the internet)? It is when a person lacks for his livelihood. When all a person's physical needs are taken care of, then he can completely focus on his service of Hashem and his Torah learning.
Similar to the times of Moshiach when our sole occupation will be learning Torah, when the Jews left Mitzrayim, they were headed toward forty years of Torah learning - nonstop! This would only be possible if they would have no worries in regards to their livelihood. Of course they would experience the miracle of the Mon falling, but that was something that they didn't 'have in the bag.' The fact that their 'safety deposit box' was full was what perhaps could give them the reassurance that there was nothing to worry about. All their needs were guaranteed by the wealth they Providentially left Mitzrayim with. This allowed them the peace of mind to focus all their efforts on their learning for the ensuing forty years.
It is no coincidence that this wealth was collected by Yosef, and set aside by him as well, for the Jewish people's redemption from Egypt, as well as the Jewish people's ultimate redemption. His job was to provide for the physical welfare of his people, so they could focus their undivided efforts on spiritual pursuits.