Turn the enchanted books you find into permanent villager trades. Hand a villager a book and it learns that enchantment, priced in emeralds. Give it a matching book later and the trade levels up by anvil rules. Works with modded enchantments.
Dying costs you hearts, not your inventory. Set how many hearts a death takes, how many deaths it takes to lose one, and a floor you can never fall below - so only the hearts you earned are ever at risk.