There’s a famous Yalkut Shimoni (Nach 1056:18, referenced by Rashi in explaining Megillah 15a), which reads as follows:
א"ר חסדא זה בא בפרוזבולי וזה בא בפרוזבוטי, פעם אחת נתן המלך ממון ושגרם בראשי גייסות לכבוש את המדינה, נטל המן ממון שלו ואכלו ולא נשתייר לו ממון, כשבא להוציא על בעלי מלחמה לא היה בידו כלום, אבל מרדכי חצי של ממון היה בידו, בא המן אצל מרדכי אמר לו לויני ממון זה שבידך אמר לו אין אני מלוך אלא אם כן תמכור נפשך לעבד לי, קבל על נפשו והלוהו, וכתב לו הרי המן עבדו של מרדכי, זבין נפשיה למרדכי בטולמא דנהמא
Rav Chisda said: [Mordechai] came as a rich man, and [Haman] came as a poor man. Once, the king gave money, and when the heads of troops caused to conquer the country, Haman took his money, depleted it, and had nothing left. When he came to go out over the commanders of war, he didn’t have anything, but Mordechai had half of the money. Haman came to Mordechai and said to him, “Lend me this money that you have.” He said to him, “I will not lend to you unless you sell yourself as a slave to me.” He accepted it, and he lent him, and he wrote for him, “Behold, Haman is Mordechai’s slave; he sold himself to Mordechai for a loaf of bread.”
When did this story take place? Was the king in the story Achashveirosh, or a previous king?