In Genesis
Joseph was sold to Egyptians as a slave by his brothers who decided to make money off him instead of killing him then became in charge of Egypt
Joseph son of Israel / Jacob knew the Egyptians were going to be given seven years of plenty followed by seven years of famine
He then scammed & robbed people taxing them of their own grain
When they were starving he let them have their own grain that he stole from them on the condition that they became his slaves